最近使用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)