1. 程式人生 > >MySQL: ERROR 1040: Too many connections”異常情況處理

MySQL: ERROR 1040: Too many connections”異常情況處理

經常會遇到”MySQL: ERROR 1040: Too many connections”的異常情況,很多時原因是使用了預設最大連線數或設定過少

檢視目前最大連線數

mysql> show variables like '%max_connections%';

+-----------------+-------+

| Variable_name | Value |

+-----------------+-------+

| max_connections | 300 |

+-----------------+-------+

1 row in set (0.00 sec)

方法1:使用set GLOBAL max_connections

mysql> set GLOBAL max_connections=3000;

Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%max_connections%';

+-----------------+-------+

| Variable_name | Value |

+-----------------+-------+

| max_connections | 3000 |

+-----------------+-------+

1 row in set (0.00 sec)

方案2:在mysql配置檔案新增或修改max_connections值

vim /etc/mysql/mysql.conf.d/mysqld.cnf

max_connections=3000

此方案需重啟mysql服務

注意:重啟後最大連線數有可能還是214,需修改檔案/lib/systemd/system/mysql.service新增

LimitNOFILE=65535

LimitNPROC=65535

儲存後重啟mysql服務即可生效

systemctl daemon-reload

systemctl restart mysql.service