mysql kill process resolves a deadlock

Source: Internet
Author: User

1. View the list of processes and find the ID

SHOW processlist

2, the query statement to lock the table, hurriedly find the first locked thread_id, in the shell of MySQL execution.

Kill ID

#!/bin/bash
Mysql-u root-e "Show Processlist" | Grep-i "Locked" >> locked_log.txt

For line in ' Cat Locked_log.txt | awk ' {print '} '
Do
echo "Kill $line;" >> Kill_thread_id.sql
Done

Now Kill_thread_id.sql's content looks like this.

Kill 66402982;
Kill 66402983;
Kill 66402986;
Kill 66402991;
.....

Well, we execute it in the shell of MySQL and we can kill all the lock-list processes.

Mysql>source Kill_thread_id.sql

Of course, it can be done in one line.
For ID in ' Mysqladmin processlist | Grep-i Locked | awk ' {print '} '
Do
Mysqladmin Kill ${id}
Done

;

mysql kill process resolves a deadlock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.