天天看點

網站時常出現too many connection的錯誤

安裝了一個程式,大通路量測試的時候發現竟然連接配接不上資料庫了,仔細檢查發現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中的操作      
[root@chy01 ~]# vim /etc/my.cnf
[mysqld]
max_connections = 500