[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid
==================== 基础设置 ====================
default-storage-engine = InnoDB
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
max_allowed_packet = 128M
open_files_limit = 65535
==================== 连接 & 线程 ====================
max_connections = 2000
max_connect_errors = 1000
wait_timeout = 600
interactive_timeout = 600
thread_cache_size = 300
table_open_cache = 4096
table_definition_cache = 4096
==================== InnoDB 核心优化(最重要) ====================
innodb_buffer_pool_size = 12G # 机器内存的 50%~70%
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1 # 强一致性(主库1,从库2)
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
==================== 慢查询 & 监控 ====================
slow_query_log = 1
slow_query_log_file = /var/lib/mysql/slow.log
long_query_time = 1
log_queries_not_using_indexes = 0
==================== GTID & 主从(你现在环境必备) ====================
gtid_mode = ON
enforce_gtid_consistency = ON
log_slave_updates = 1
==================== 只读从库优化(你现在的环境) ====================
read_only = ON
super_read_only = ON
==================== 临时表 & 排序 ====================
tmp_table_size = 256M
max_heap_table_size = 256M
sort_buffer_size = 4M
join_buffer_size = 4M
