Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

kill slow queries mysql

# MySQL queries can sometimes be long-running and may prevent transactions from accessing necessary tables to complete a request. This will put your users on hold. In order to kill these long-running queries, you must access the environment’s MySQL database.
# Correcting Long-Running Queries
# When you are able to successfully make a local MySQL connection to the site’s database, run the ensuing command to present a list of accessible threads:
# Show processlist;


# Then review the “Time” field to find the longest running query
# Next, run the following command to kill it:


kill thread_ID;

 
# As a side note, be sure to replace <thread_id> with the ID of the query you want to deactivate or get rid of.


Kill All Queries


# If multiple bad requests are preventing valid queries from working, you can fix this by clearing them out without having to run kill on individual threads. 
Perform the following to produce kill commands from the PROCESSLIST table:


mysql> SELECT GROUP_CONCAT(CONCAT('KILL ',id,';') SEPARATOR ' ') 
 
FROM information_schema.processlist WHERE user <> 'system user';

# The final step is to copy the provided query in the output and run as instructed. This will fix your queries problem!
 
PREVIOUS NEXT
Tagged: #kill #slow #queries #mysql
ADD COMMENT
Topic
Name
5+4 =