How to update the max_connections in MySQL
The “too many connections” error during a database query occurs when the number of connections exceeds max_connections. MySQL normally permits max_connections+1 connections: max_connections is the maximum number allowed, and the extra connection is for a superuser.
The default max_connections is 100 for versions earlier than 5.1.15 and 151 for later versions. The maximum configurable value is 16384 in versions 5.1.15–5.1.16, and 100000 from version 5.1.17 onward.
Check max_connections with this command in the MySQL command line tool:
mysql> show global variables like "max_connections";
+------------------------+---------+
| Variable_name | Value |
+------------------------+---------+
| max_connections | 300 |
+------------------------+---------+
1 row in set (0.00 sec)
There are two ways to set max_connections: Method 1: Use the command line. This changes the value temporarily without a restart. First log in to the MySQL command line tool. For example, set the maximum number of connections to 300:
mysql> set global max_connections = 300;
Method 2: Edit /etc/my.cnf. Add the desired max_connections value under [mysqld], as shown below:
[mysqld]
max_connections = 300 //กำหนดให้จำนวน connections มากที่สุดเท่ากับ 300
Then restart MySQL:
# Service mysqld restart
Increasing max_connections also increases RAM use, so do not raise it beyond what is needed. A suitable max_connections value for Linux or Solaris is between 500 and 1000. If you have plenty of spare RAM (> 1GB), you can set it higher.