Before stopping MySQL from running queries, we first need to see how many processes there are.
Run using show command.The query is as follows −
mysql> show processlist;
After executing the above query, we will get the output with some id's. This is given as follows −
+----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ | 4 | event_scheduler | localhost | NULL | Daemon | 71034 | Waiting on empty queue | NULL | | 8 | Manish | localhost:53496 | business | Query | 0 | starting |show processlist| +----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ 2 rows in set (0.00 sec)
As seen from the above output, the db currently in use is 'business'. and its id is 8. To stop the Query command calls can be used with an ID given a list of running processes. Its syntax is: is as follows −
call mysql.rds_kill(valueOfGivenIdInProcesslist);
Now, the above syntax is applied to the query and valueOfGivenIdInProcesslist is put as 8. This Shown below is −
mysql> CALL mysql.rds_kill(8);
After executing the above query, I get the following output −
ERROR 2013 (HY000): Lost connection to MySQL server during query
This happens when the above query stops running. Use the `use` command to check if it has
stopped or not. The syntax for that is as follows −use yourDatabaseName;
The above syntax is applied to the mydatabase name ‘business’ in the system. The query is as follows −
mysql> use business;
After executing the above query, I get the following output −
No connection. Trying to reconnect... Connection id: 10 Current database: *** NONE *** Database changed mysql>
So, it is obvious that the query has stopped because the message is "Trying..." In MySQL, "reconnect..."" means to reconnect. It also displays the current database as "none". After a period of time, Time for the connection to the database to be restored.
The above is the detailed content of How do I stop a MySQL query from running?. For more information, please follow other related articles on the PHP Chinese website!