mysql有一些设置在重启服务器的时候是很有必要添加的。
如:最大连接数(max_connections),最大包大小(max_allowed_packet),默认编码格式,以及sql_mode
以下为一个我个人比较常用的mysql配置文件
当然后面部分标注了更新的内容是我后面遇到实际问题添加的一些参数,所以没有写的太具体。
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
character-set-server = utf8 #设置默认编码utf8
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
log_bin=mysql-bin
expire_logs_days=7
server_id=1
#开启登录时记录相关登录信息
init-connect='insert into accesslog.accesslog(id, time, localname, matchname) values(connection_id(),now(),user(),current_user());'
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql #设置数据存储路径
socket=/var/lib/mysql/mysql.sock
max_allowed_packet = 66M #设置最大包大小
max_connections=10000 #设置最大连接数
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#设置默认编码utf8
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
#更新
#如果在创建函数的时候报错(deterministic ,nosql,read sql)
#可以添加以下内容重启服务器
log_bin_trust_function_creators=1
#更新
sql update 安全模式
SET GLOBAL SQL_SAFE_UPDATES = 1;
#更新
对于大表:
innodb_data_file_path设置autoextend
加大
tmp_table_size 临时表大小设置,不要过大
max_heap_table_size 最大内存表设置,不要过大
#更新
group_concat_max_len = 200000
concat函数
#服务器相关优化
query_cache_size:用于缓存查询的内存大小
table_cache:mysql同一时间内保持大开的table的数量
#存储引擎相关优化
innodb_buffer_pool_size 缓冲池字节大小
MySQL5.7.5对于Buffer的分配需要提前计算一下。 尽量让
innodb_buffer_pool_size= innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
从而获取一个较佳的性能。
innodb_buffer_pool_chunk_size默认是128M.
innodb_log_buffer_size 写入日志文件缓冲字节数
innodb_log_file_size 每个日志文件字节大小