MySQL5.7连接数调优
环境:
MySQL:5.7
问题描述
MySQL提示连接数太多
解决办法
查看最大连接数
SHOW VARIABLES LIKE "max_connections";
修改最大连接数
SET GLOBAL max_connections = 300;
或修改my.cnf,增加
[mysqld]
max_connections = 300
docker版mysql,可以增加command --max-connections=300
:
mysql:
image: "mysql:5.7"
ports:
- "3306:3306" # 宿主机监听端口:容器内部端口
command:
- "--default-authentication-plugin=mysql_native_password"
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
- "--lower-case-table-names=1"
- "--max-allowed-packet=100M"
- "--wait-timeout=601"
- "--max-connections=300"
environment:
MYSQL_ROOT_PASSWORD: 123456
volumes:
- /data/mysql:/var/lib/mysql
相关调试命令
show status like 'Threads%';
SHOW PROCESSLIST;
SHOW FULL PROCESSLIST;
show variables like 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
SHOW VARIABLES LIKE '%max_connections%';
SHOW STATUS LIKE '%Connection%';