Problem: The website suddenly error, show "Too many connections ..." What is this?
Solve:
A few useful actions are listed first:
① mysql -u root -p
Enter the password into MySQL
② show processlist;
View the number of connections, you can find that there are many connections in sleep state, these are actually temporarily useless, so you can kill
③ show variables like "max_connections";
View the maximum number of connections, which should be the same as the number of connections queried above, before too many connections is present
④ set GLOBAL max_connections=1000;
Modify the maximum number of connections, but this is not a once and for all method, you should let it automatically kill those sleep processes.
⑤ show global variables like ‘wait_timeout‘;
This value refers to the number of seconds that MySQL waits before closing a non-interactive connection, which defaults to 28800s
⑥ set global wait_timeout=300;
Modify this value, here can be arbitrary, preferably control in a few minutes
⑦ set global interactive_timeout=500;
Modify this value to indicate the number of seconds that MySQL waits before closing a connection, so that MySQL automatically shuts down those useless connections, but be aware that the connection that is being used is also turned off , so this time value should be appropriate
My workaround:
① select concat(‘KILL ‘,id,‘;‘) from information_schema.processlist where user=‘root‘;
First query the connection ID to kill
② Copy the middle of thekill id;
③ Copy the modified content back to the terminal, and then press ENTER to execute
Database Too many connections workaround