Home > Article > Backend Development > 008 A solution to PHP database 1040 too many connections
I wrote a scheduled task to frequently request an interface, and this error occurred. It seemed that too many processes were blocking the database. The first is to stop the scheduled task, then enter the database and enter show processlist; then kill the redundant processes. However, if there are too many processes, it is troublesome to delete them individually. A master has written a shell script to delete these processes in batches, for i in `mysql -uroot -p123 -h127.0.0.1 -e "show processlist"|grep -v 'Id'|awk '{print $1}'`; do mysql -uroot -p12345 -h10.10.14.18 -e "kill $i"; done;
-p is followed by the database password, and -h is followed by your own host. If you want to connect directly, delete the host. This will work too
for i in `mysql -uroot -p123 -e "show processlist"|grep -v 'Id'|awk '{print $1}'`; do mysql -uroot -p12345 -e "kill $i"; done;
that's it.
Related recommendations:
PHP database addition, deletion, modification query
PHP database is based on PDO operation class (mysql)
The above is the detailed content of 008 A solution to PHP database 1040 too many connections. For more information, please follow other related articles on the PHP Chinese website!