| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- [mysqld]
- # ===== 基础设置 =====
- datadir = /data/mysql/data/mysql
- socket = /data/mysql/data/mysql/mysql.sock
- port = 13306
- user = root
- # ===== 日志设置 =====
- log-error = /data/mysql/log/mysqld.log
- pid-file = /var/run/mysqld/mysqld.pid
- # 关闭慢查询日志以减少IO和内存开销
- slow_query_log = 0
- # ===== 连接和线程设置 =====
- # 连接池设置(4G内存优化)
- max_connections = 800
- max_connect_errors = 10000
- back_log = 500
- # 线程缓存(增加连接数后相应调整)
- thread_cache_size = 64
- # 连接超时设置
- connect_timeout = 10
- wait_timeout = 1800
- interactive_timeout = 1800
- # ===== 内存和缓存设置(小内存优化) =====
- # InnoDB缓冲池(4G内存下优化为70%)
- # 4G内存:800M缓冲池,4个实例
- innodb_buffer_pool_size = 800M
- innodb_buffer_pool_instances = 4
- # InnoDB日志设置(适当减小)
- innodb_log_file_size = 64M
- innodb_log_files_in_group = 2
- innodb_log_buffer_size = 8M
- # 其他InnoDB设置
- innodb_flush_log_at_trx_commit = 1
- innodb_flush_method = O_DIRECT
- innodb_file_per_table = 1
- innodb_open_files = 1024
- # 关闭查询缓存
- query_cache_type = 0
- query_cache_size = 0
- # 表缓存(增加连接数后相应调整)
- table_open_cache = 2048
- table_definition_cache = 1024
- # ===== 高并发优化(精简版) =====
- # InnoDB并发设置
- innodb_thread_concurrency = 0
- innodb_read_io_threads = 4
- innodb_write_io_threads = 4
- # 锁和事务设置
- innodb_lock_wait_timeout = 30
- transaction_isolation = READ-COMMITTED
- # 排序和临时表(4G内存下适当增加)
- sort_buffer_size = 256K
- read_buffer_size = 128K
- read_rnd_buffer_size = 256K
- join_buffer_size = 256K
- tmp_table_size = 32M
- max_heap_table_size = 32M
- # ===== 网络和包设置 =====
- max_allowed_packet = 16M
- # ===== 性能和安全 =====
- # 关闭性能模式以减少内存占用
- performance_schema = OFF
- # 安全限制(增加最大连接数)
- max_user_connections = 500
- skip_name_resolve = 1
- # ===== 其他优化 =====
- # 字符集
- character-set-server = utf8mb4
- collation-server = utf8mb4_unicode_ci
- # 默认存储引擎
- default_storage_engine = InnoDB
- # 禁止符号链接
- symbolic-links = 0
- [client]
- port = 13306
- socket = /data/mysql/data/mysql/mysql.sock
- default-character-set = utf8mb4
- [mysql]
- default-character-set = utf8mb4
- [mysqld_safe]
- log-error = /data/mysql/log/mysqld.log
- pid-file = /var/run/mysqld/mysqld.pid
|