Sometimes you run test queries against large databases, or you copy & paste a query but leave out the where clause, or otherwise make a mess. If you ever accidentally execute a query in MySQL that spikes the CPU, here’s how you kill or stop it:
show processlist;
That will return a list describing what’s going on in MySQL. Hopefully the result set is small enough that you can pinpoint your slow query. Look for a row with a large value for the Time column and something other than Sleep in the Command column. Look at the rest of the columns to be sure you’ve found what you’re looking for.
| Id | User | Host | db | Command | Time | State | Info |
| 21445 | john | localhost | products_db | Query | 94 | Sending data | select * from users inner join posts |
Once you’re sure you have the right one, use the kill command (note: this is the MySQL kill command for killing MySQL internal threads, not the OS-level command for killing processes!).
kill query 21445;