修改Mysql最大鏈接數

最近使用Mysql數據庫進行多編程操做時報錯:ERROR 1040: Too many connections 。提示鏈接過多,檢查發現Mysql的默認鏈接數爲151,可根據實際狀況進行修改。mysql

一、查看最大鏈接數設置
mysql -uroot -p

MariaDB [(none)]>  show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.01 sec)
二、查看實際己使用的最大鏈接數

能夠發現實際使用的鏈接數己達到最大鏈接數限制sql

MariaDB [(none)]> show global status like 'Max_used_connections';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 152   |
+----------------------+-------+
1 row in set (0.01 sec)
三、根據實際須要修改最大鏈接數
MariaDB [(none)]>  set GLOBAL max_connections=4096; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>  show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 4096  |
+-----------------+-------+
1 row in set (0.01 sec)
四、再次運行報錯程序,檢查己使用最大鏈接數
MariaDB [(none)]> show global status like 'Max_used_connections';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 1002  |
+----------------------+-------+
1 row in set (0.01 sec)
相關文章
相關標籤/搜索