安装了一个程序,大访问量测试的时候发现竟然连接不上数据库了,仔细检查发现MySQL数据库出现1040错误,提示“too many connections”。那么改如何解决这个问题呢?
其实MySQL默认的最大连接数为100,可能在大访问量的时候造成了连接不上数据库。
解决的办法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | mysql版本:mysql> select version(); +------------+ | version() | +------------+ | 5.6.35-log | +------------+ 1 row in set (0.00 sec) mysql> show variables like 'max_connections' ; // 查看mysql的最大连接数可以看到是150 +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 150 | +-----------------+-------+ 1 row in set (0.01 sec) mysql> set GLOBAL max_connections=500; // 更改连接数,这里的连接数要根据访问量更改,可以看到我更改时出现了如下的问题。 ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation [root@chy01 ~] # vim /etc/my.cnf [mysqld] skip-grant-tables // 跳过权限验证。 保存退出 mysql> set GLOBAL max_connections=500; // 再次修改 Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'max_connections' ; // 修改成功 +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 500 | +-----------------+-------+ 1 row in set (0.00 sec) 如上是在mysql中的操作 |
如果想要一直生效需要在配置文件中修改,但是需要重启mysql服务。(线上服务器谨慎操作)
1 2 3 | [root@chy01 ~] # vim /etc/my.cnf [mysqld] max_connections = 500 |
希望看过的童鞋多多指教,谢谢!
本文转自我不是瘦子51CTO博客,原文链接:http://blog.51cto.com/chy940405/1980022,如需转载请自行联系原作者