1.查看当前所有连接的详细资料:
mysqladmin -uroot -proot processlist
客户端使用:
show full processlist
2、只查看当前连接数(Threads就是连接数.):
mysqladmin -uroot -proot status
客户端使用:
3.查看最大连接数
show variables like "max_connections";
4:查看当前连接数:
show global status like 'Max_used_connections';
如果进程过多打印下来:
mysql -e 'show full processlist;' > 111
解决办法:
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
set global wait_timeout=100;
SET GLOBAL interactive_timeout=100;
修改连接的等待时间,超过时间释放连接。
上面是实时修改重启数据库后失效
可在my.cnf中添加
wait_timeout=100
interactive_timeout=100
再次查看可能发现连接任然无法释放。需要重启数据库。
可能Shutdown mysqld失败。一直.............................................................................................
则重启服务器吧。【摊手】
mysql数据库无响应状态了。只能强制重启了
还可以修改最大连接数(不建议):
MySQL服务器过去的最大连接数是245,没有达到服务器连接数上限256,应该没有出现1040错误,比较理想的设置是:
Max_used_connections / max_connections * 100% ≈ 85%
临时修改
set GLOBAL max_connections=1000;
永久修改:
配置/etc/my.cnf
[mysqld]新添加一行如下参数:
max_connections=1000
show variables like 'max_connections';
如果不是我们查看的最大1000;
这是由于mariadb有默认打开文件数限制。可以通过配置/usr/lib/systemd/system/mariadb.service来调大打开文件数目。
配置/usr/lib/systemd/system/mariadb.service
[Service]新添加两行如下参数:
LimitNOFILE=10000
LimitNPROC=10000
重新加载系统服务,并重启mariadb服务
systemctl --system daemon-reload
systemctl restart mariadb.service