MySQL 常用配置文件


MySQL 常用配置文件


正文

对于MySql下面的各种参数的一旦配置,很少变动,时间长了容易忘记其作用,在需要改变某项参数的时候,还要到处查找其含义, 现对MySql下面的配置文件my.cnf重要选项做一个说明,方便随时查阅。

位置

编译安装的时候在SYSCONFDIR选项配置的路径下,一般在/etc/下。

二进制安装的位置取决于启动选项--defaults-file,一般也设置在/etc/下。

重要选项说明

my.cnf

# The Percona Server 5.7 configuration file.
[client]
port = 3306
socket = /data/mysql/3306/mysql3306.sock
[mysqld]
performance_schema = off
log_timestamps = SYSTEM
server-id = 1611147 #实例唯一ID,主从不能重复
user = mysql #启动用户
port = 3306  #服务端口
socket = /data/mysql/3306/mysql3306.sock #套接字、pid、数据目录、日志目录设置
pid-file = /data/mysql/3306/mysql3306.pid
datadir = /data/mysql/3306
log_bin = /data1/binlog/3306/mysql-bin
relay_log = /data1/binlog/3306/mysql-relay
log_error =/data/mysql/3306/mysqld.log
slave_load_tmpdir=/data/mysql/3306/
tmpdir=/data/mysql/3306/ #查询产生的临时文件目录
lower_case_table_names=1
skip-slave-start
skip-name-resolve
back_log = 3000
max_connections = 16024 #最大连接数
sql-mode = ""
max_connect_errors = 100
table_open_cache = 2000
binlog_cache_size = 2048KB
read_buffer_size = 1M
read_rnd_buffer_size = 1M
sort_buffer_size = 2M #排序缓存
join_buffer_size = 2M #连接缓存
thread_cache_size = 100
query_cache_size = 0
ft_min_word_len = 4
default-storage-engine = InnoDB
thread_stack = 192K
transaction_isolation = READ-COMMITTED #事务隔离级别
tmp_table_size = 8M
max_heap_table_size = 8M
binlog_format=ROW
log_slave_updates=ON
log_warnings
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
max_allowed_packet = 1024M
sync_binlog = 1000
expire_logs_days = 7 #binlog过期时间
max_binlog_size = 1G #binlog文件大小设置
net_write_timeout = 120
binlog-ignore-db=information_schema
sync_master_info = 1000
binlog_rows_query_log_events = 0
open-files-limit = 65535
max_relay_log_size = 1G 
relay_log_purge = 1
relay_log_recovery = 1
master_info_repository = 'TABLE' #从库以表的方式保存主库的binlog信息
skip_slave_start = 1
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16 #从库复制线程数
relay_log_info_repository=TABLE #从库以表方式保存中继日志信息
slave_preserve_commit_order=1
slow_query_log=ON #慢查询设置
slow_query_log_file =/data/mysql/3306/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 2000
expire_logs_days = 10
long_query_time = 1
min_examined_row_limit = 0
explicit_defaults_for_timestamp = 1
thread_handling = pool-of-threads
thread_pool_oversubscribe = 10
innodb_read_io_threads = 4 #读写线程数
innodb_write_io_threads = 4
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size = 48G #buffer pool缓存大小,一般不超过物理内存的75%
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 1024
innodb_lock_wait_timeout = 50
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_flush_neighbors = 1
innodb_log_file_size = 2G #事务日志文件大小设置
innodb_purge_threads = 1
innodb_large_prefix = 0
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 1048576
innodb_data_file_path = ibdata1:512M;ibdata2:512M:autoextend
innodb_log_buffer_size = 8M
innodb_file_per_table = 1
innodb_max_dirty_pages_pct = 75
innodb_lock_wait_timeout = 120
innodb_log_files_in_group = 3
#read_only = ON #只读选项,从库要这是为只读
#super_read_only = ON
wait_timeout = 180 #线程空闲等待时间
interactive_timeout = 180
character-set-server = utf8
[mysqldump]
quick
max_allowed_packet = 1024M
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 32M
write_buffer = 32M
[mysqld_safe]
open-files-limit = 65535
[mysqlhotcopy]
interactive-timeout

my.cnf

# The Percona Server 5.7 configuration file.
 
[client]
port        = 3306
socket      = /data/mysql/3306/mysql3306.sock
 
[mysqld]
performance_schema = off
log_timestamps = SYSTEM
server-id = 1611188
user = mysql
port            = 3306
socket          = /data/mysql/3306/mysql3306.sock
pid-file        = /data/mysql/3306/mysql3306.pid
datadir         = /data/mysql/3306
log_bin         = /data1/binlog/3306/mysql-bin
relay_log       = /data1/binlog/3306/mysql-relay
log_error =/data/mysql/3306/mysqld.log
slave_load_tmpdir=/data/mysql/3306/
tmpdir=/data/mysql/3306/
lower_case_table_names=1
 
skip-slave-start
skip-name-resolve
back_log = 3000
max_connections = 16024
sql-mode = ""
max_connect_errors = 100
table_open_cache = 2000
binlog_cache_size = 2048KB
read_buffer_size = 1M
read_rnd_buffer_size = 1M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 100
query_cache_size = 0
ft_min_word_len = 4
default-storage-engine = InnoDB
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 8M
max_heap_table_size = 8M
binlog_format=ROW
log_slave_updates=ON
log_warnings
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
max_allowed_packet = 1024M
sync_binlog = 1
expire_logs_days = 7
max_binlog_size = 1G
net_write_timeout = 120
binlog-ignore-db=information_schema
sync_master_info = 1000
binlog_rows_query_log_events = 0
open-files-limit = 65535
 
max_relay_log_size = 1G
relay_log_purge = 1
master_info_repository = 'TABLE'
skip_slave_start = 1
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
relay_log_info_repository=TABLE
slave_preserve_commit_order=1
 
slow_query_log=ON
slow_query_log_file =/data/mysql/3306/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 2000
long_query_time = 1
min_examined_row_limit = 0
explicit_defaults_for_timestamp = 1
thread_handling = pool-of-threads
thread_pool_oversubscribe = 10
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_flush_log_at_trx_commit = 1
innodb_buffer_pool_size = 12G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 1024
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_flush_neighbors = 1
innodb_log_file_size = 512M
innodb_purge_threads = 1
innodb_large_prefix = 0
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 1048576
innodb_data_file_path = ibdata1:512M;ibdata2:512M:autoextend
innodb_log_buffer_size = 8M
innodb_file_per_table = 1
innodb_max_dirty_pages_pct = 75
innodb_lock_wait_timeout = 220
innodb_log_files_in_group = 3
read_only = ON
#super_read_only = ON
wait_timeout = 86400
interactive_timeout = 7200
character-set-server = utf8
 
[mysqldump]
quick
max_allowed_packet = 1024M
 
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 32M
write_buffer = 32M
[mysqld_safe]
open-files-limit = 65535
 
[mysqlhotcopy]
interactive-timeout






参考资料


返回