# MySQL配置文件 - 生产环境 # 针对生产环境优化的MySQL配置 [mysqld] # 基础配置 user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking # 字符集配置 character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect = 'SET NAMES utf8mb4' # 网络配置 bind-address = 0.0.0.0 max_connections = 200 max_connect_errors = 100000 max_allowed_packet = 64M interactive_timeout = 600 wait_timeout = 600 # 缓存配置 - 生产环境优化 key_buffer_size = 256M max_allowed_packet = 64M table_open_cache = 4000 sort_buffer_size = 4M read_buffer_size = 2M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 128M thread_cache_size = 50 query_cache_type = 1 query_cache_size = 128M query_cache_limit = 2M # InnoDB配置 - 生产环境优化 innodb_buffer_pool_size = 512M innodb_log_file_size = 128M innodb_log_buffer_size = 16M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_file_per_table = 1 innodb_flush_method = O_DIRECT # 日志配置 log_error = /var/log/mysql/error.log slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 log_queries_not_using_indexes = 1 # 二进制日志配置 - 生产环境启用 log_bin = /var/log/mysql/mysql-bin.log binlog_format = ROW expire_logs_days = 7 max_binlog_size = 100M # 安全配置 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION [mysql] default-character-set = utf8mb4 [client] default-character-set = utf8mb4