安装了一个程序,大访问量测试的时候发现竟然连接不上数据库了,仔细检查发现MySQL数据库出现1040错误,提示“too many connections”。那么改如何解决这个问题呢?
其实MySQL默认的最大连接数为100,可能在大访问量的时候造成了连接不上数据库。
解决的办法:
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服务。(线上服务器谨慎操作)
[root@chy01 ~]# vim /etc/my.cnf[mysqld]max_connections = 500
希望看过的童鞋多多指教,谢谢!650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0063.gif" alt="j_0063.gif" style="padding:0px;margin:0px;vertical-align:top;border:none;" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0063.gif" alt="j_0063.gif" style="padding:0px;margin:0px;vertical-align:top;border:none;" />
网站时常出现too many connection的错误
原文地址:http://chy940405.blog.51cto.com/11344281/1980022