在使用MySQL数据库的时候,常常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是由于访问MySQL且还未释放的链接数目已经达到MySQL的上限。mysql
max_connections 是指整个mysql服务器的最大链接数;
max_user_connections 是指每一个数据库用户的最大链接数,好比:虚拟主机能够用这个参数控制每一个虚拟主机用户的数据库最大链接数;sql
查看mysql的数据库链接数数据库
(1),使用命令服务器
select @@max_connections;code
(2),使用命令server
show variables like 'max_connections';io
修改mysql的链接数为sed
临时有效,重启服务器无效:配置
set
global
max_connections=1000;(设置最大链接数为1000,能够再次查看是否设置成功)
select
永久有效,修改mysql的配置文件
添加
参数max_connections,将其改成max_connections=1000,而后重启MySQL便可
查看max_used_connections,
设置max_connections能够依据下面公式做为参考:
Max_used_connections / max_connections * 100% ≈ 85% 响应链接数占上限链接数的85%左右,若是发现比例在10%如下,MySQL服务器链接上线就设置得太高了。