mysql优化参数
以下1核1G1M为阿里云标配,内存1G,可使用内存为:561.63MB,参数上面一行为建议内存,下面一行为预计最大占用内存 | |||||||
1G |
1 - 2G 467.25MB |
2 - 4G 1440.50MB |
4 - 8G 2955.5MB |
8 - 16G 6601.0MB |
16 - 32G 14812MB |
||
key_buffer_size | 8 | 32 | 192 | 384 | 512 | 1024 | MB, 用于索引的缓冲区大小 |
query_cache_size | 4 | 16 | 64 | 128 | 256 | 384 | MB, 查询缓存,不开启请设为0 |
tmp_table_size | 8 | 64 | 384 | 512 | 1024 | 2048 | MB, 临时表缓存大小 |
innodb_buffer_pool_size | 16 | 64 | 128 | 384 | 1024 | 4096 | MB, Innodb缓冲区大小 |
innodb_log_buffer_size | 8 | 8 | 8 | 8 | 8 | 8 | MB, Innodb日志缓冲区大小 |
sort_buffer_size | 256 | 768 | 768 | 1024 | 2048 | 4096 | KB * 连接数, 每个线程排序的缓冲大小 |
read_buffer_size | 128 | 768 | 768 | 1024 | 2048 | 4096 | KB * 连接数, 读入缓冲区大小 |
read_rnd_buffer_size | 256 | 512 | 512 | 768 | 1024 | 2048 | KB * 连接数, 随机读取缓冲区大小 |
join_buffer_size | 128 | 512 | 1024 | 2048 | 4096 | 4096 | KB * 连接数, 关联表缓存大小 |
thread_stack | 256 | 256 | 256 | 256 | 256 | 256 | KB * 连接数, 每个线程的堆栈大小 |
binlog_cache_size | 32 | 64 | 64 | 128 | 192 | 256 | KB * 连接数, 二进制日志缓存大小(4096的倍数) |
thread_cache_size | 4 | 8 | 16 | 32 | 48 | 64 | 线程池大小 |
table_open_cache | 32 | 128 | 192 | 256 | 512 | 1024 | 表缓存(最大不要超过2048) |
max_connections | 500 | 100 | 200 | 300 | 400 | 500 | 最大连接数 |
mysql 配置参数
C/C++ Code复制内容到剪贴板
- [client]
- #password = your_password
- port = 3306
- socket = /tmp/mysql.sock
- [mysqld]
- port = 3306
- socket = /tmp/mysql.sock
- datadir = /www/server/data
- default_storage_engine = MyISAM
- #skip-external-locking
- #loose-skip-innodb
- key_buffer_size = 8M
- max_allowed_packet = 100G
- table_open_cache = 32
- sort_buffer_size = 256K
- net_buffer_length = 4K
- read_buffer_size = 128K
- read_rnd_buffer_size = 256K
- myisam_sort_buffer_size = 4M
- thread_cache_size = 4
- query_cache_size = 4M
- tmp_table_size = 8M
- #skip-networking
- #skip-name-resolve
- max_connections = 500
- max_connect_errors = 100
- open_files_limit = 65535
- log-bin=mysql-bin
- binlog_format=mixed
- server-id = 1
- expire_logs_days = 10
- innodb_data_home_dir = /www/server/data
- innodb_data_file_path = ibdata1:10M:autoextend
- innodb_log_group_home_dir = /www/server/data
- innodb_buffer_pool_size = 16M
- innodb_additional_mem_pool_size = 2M
- innodb_log_file_size = 5M
- innodb_log_buffer_size = 8M
- innodb_flush_log_at_trx_commit = 1
- innodb_lock_wait_timeout = 50
- [mysqldump]
- quick
- max_allowed_packet = 16M
- [mysql]
- no-auto-rehash
- [myisamchk]
- key_buffer_size = 20M
- sort_buffer_size = 20M
- read_buffer = 2M
- write_buffer = 2M
- [mysqlhotcopy]
- interactive-timeout