The reason for this error is that the amount of traffic is really high, the MySQL server will not hold, this time to consider increasing the read pressure from the server spread, the other is the MySQL configuration file max_connections value is too small.
Analyze the reason
MySQL's default connection is only 100, that is, the connection data over 100 will likely appear Too Many connections
Modify MY.CNF profile Add and reboot required:
[Mysqld]
Wait_timeout = 600
Interactive_timeout = 600
Query the maximum number of MySQL connections:
The code is as follows |
Copy Code |
Mysql> Show variables like ' max_connections '; +-----------------+-------+ | variable_name | Value | +-----------------+-------+ | max_connections | 100 | +-----------------+-------+ 1 row in Set (0.00 sec) |
Maximum number of connections to query MySQL response:
The code is as follows |
Copy Code |
Mysql> show global status like ' Max_used_connections '; +----------------------+-------+ | variable_name | Value | +----------------------+-------+ | max_used_connections | 5 | +----------------------+-------+ 1 row in Set (0.00 sec) |
Description: The local environment is not a reference value, but in the above data, MySQL in the past to respond to the maximum number of connections is less than the maximum number of connections allowed, so there will be no 1040 errors.
MySQL is ideal for the maximum number of connections calculated by:
The code is as follows |
Copy Code |
Max_used_connections/max_connections * 100%≈85% |
That is, the maximum number of connections to the upper limit of 85% of the number of connections, if the ratio is found below 10%, MySQL server connection number of the upper limit set too high.
problem to find a solution
1, Mysql-u root-p can not enter, the same error occurred.
2, modify/ETC/MYSQL/MY.CNF (Ubuntu system, other systems in/ETC/MY.CNF
The code is as follows |
Copy Code |
[Mysqld] port=3306 #socket =mysql Skip-locking Set-variable = key_buffer=16k Set-variable = max_allowed_packet=1m Set-variable = thread_stack=64k Set-variable = table_cache=4 Set-variable = sort_buffer=64k Set-variable = net_buffer_length=2k Set-variable = max_connections=1000 |
3, restart
The code is as follows |
Copy Code |
Mysql/etc/init.d/mysql restart |
It's done.