Introduction
Whether due to a "too many database connections" error or otherwise, sometimes you may need to terminate MySQL connections on your cPanel server.
Procedure
The quickest way to kill all MySQL connections would be to simply restart the MySQL service. This can be done via "Restart Services" in WHM, or via the command-line.
-bash-4.2# /scripts/restartsrv_mysql
It is also possible to kill individual connections for the MySQL client. You can access this client by issuing the MySQL command from a root SSH session.
-bash-4.2# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
At this point, you can show the process list and then kill individual process IDs.
mysql> SHOW PROCESSLIST;
+-----+------+-----------------+------+---------+------+-------+---------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------------+------+---------+------+-------+----------------+
| 111 | root | localhost:61199 | test | Query | 0 | init | SHOW PROCESSLIST |
| 222 | root | localhost:23543 | test | Sleep | 10 | | NULL |
+-----+------+-----------------+------+---------+------+-------+----------------+
2 rows in set (0.00 sec)
mysql> KILL 222;
Query OK, 0 rows affected (0.00 sec)
Comments
0 comments
Article is closed for comments.