在实际项目中我们需要改变mysql的最大连接数;通常,mysql的最大连接数默认是100, 最大可以达到16384。明显对于稍微大点的项目100个链接是远远不够的
方式一:通过show语句查看
show variables like '%max_connections%';
方式二:通过查看my.ini配置文件
# The maximum amount of concurrent sessions the MySQL server will # allow. One of these connections will be reserved for a user with # SUPER privileges to allow the administrator to login even if the # connection limit has been reached. max_connections=100
进入MySQL安装目录,打开MySQL配置文件my.ini或my.cnf查找配置文件,找到如下信息(max_connections):
# The maximum amount of concurrent sessions the MySQL server will # allow. One of these connections will be reserved for a user with # SUPER privileges to allow the administrator to login even if the # connection limit has been reached. max_connections=100
将max_connections修改为你需要的连接数,如:
max_connections=1000
然后重新启动mysql就搞定了;
命令行登录MySQL后。设置新的MySQL最大连接数为200:
MySQL> set global max_connections=200
这种方式有个问题,就是设置的最大连接数只在mysql当前服务进程有效,一旦mysql重启,又会恢复到初始状态。因为mysql启动后的初始化工作是从其配置文件中读取数据的,而这种方式没有对其配置文件做更改。