mysql - 优化(max_connection, thread_cache_size 等的设置)
访问量: 2401
参考: https://serverfault.com/questions/408845/what-value-of-thread-cache-size-should-i-use
今天我们的服务器的自我检测程序停掉了.
原因很有意思,mysql 的最大连接数超过了上线, 报错.
结局办法: (修改配置文件之后记得重启)
修改 mysql的配置 (/etc/mysql/my.cnf ) 设置
[mysqld]
max_connections = 2000
或者更高.
另外, thread_cache_size 也需要设置, 设置办法:
1. 查看3个参数;
mysql> show global status like 'Connections' -> ; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Connections | 368 | +---------------+-------+ mysql> show global status like 'Threads_created'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | Threads_created | 181 | +-----------------+-------+ mysql> show global status like 'Max_used_connections'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | Max_used_connections | 152 | +----------------------+-------+
然后, Threads_created / Connections 如果 > 0.01 那么 就需要增加 thread_cache_size
thread_cache_size 必须要高于 Max_used_connections .