Debian MariaDB性能调优参数设置
一 基线配置与配置文件路径
二 核心参数建议
三 不同内存规格的示例配置
说明:以下为 [mysqld] 段示例片段,按总内存与负载特性微调;变更 innodb_log_file_size 需按官方步骤替换日志文件,避免直接删除旧日志导致启动失败。
4 GB 内存(通用 OLTP,读多写少)
innodb_buffer_pool_size = 2.5G
innodb_buffer_pool_instances = 2
key_buffer_size = 64M
max_connections = 200
thread_cache_size = 16
table_open_cache = 2000
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
sync_binlog = 100
tmp_table_size = 128M
max_heap_table_size = 128M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
8 GB 内存(OLTP 为主,写入较频繁)
innodb_buffer_pool_size = 6G
innodb_buffer_pool_instances = 6
key_buffer_size = 128M
max_connections = 500
thread_cache_size = 32
table_open_cache = 4000
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
16 GB 内存(高并发/写入密集)
innodb_buffer_pool_size = 12G
innodb_buffer_pool_instances = 8
key_buffer_size = 128M
max_connections = 800
thread_cache_size = 32
table_open_cache = 8000
innodb_log_file_size = 1G
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
四 应用与 SQL 层优化要点
五 监控与维护