Mysql uses the kill command to solve the deadlock problem (killing an SQL statement being executed)

Source: Internet
Author: User

Mysql uses the kill command to solve the deadlock problem (killing an SQL statement being executed)

When using mysql to run certain statements, the deadlock is caused by a large amount of data, which is not reflected. At this time, you need to kill a query statement that is consuming resources. The syntax format of the kill command is as follows: Mysql uses the kill command to solve the deadlock problem (killing an SQL statement being executed)

KILL [CONNECTION | QUERY] thread_id

Each connection to mysqld runs in an independent thread. You can use the show processlist statement to check which threads are running and use the KILL thread_id statement to terminate a thread.

KILL allows the optional CONNECTION or QUERY modifier: kill connection is the same as KILL without the modifier: It terminates the CONNECTION related to the given thread_id. Kill query terminates the statement currently being executed, but keeps the connection intact.

If you have the PROCESS permission, you can view all threads. If you have super administrator permissions, You can terminate all threads and statements. Otherwise, you can only view and terminate your own threads and statements. You can also use the mysqladmin processlist and mysqladmin kill commands to check and terminate threads.

Log on to MySQL first, and then use: show processlist; to view the status of each thread in mysql.

Mysql> show processlist;

+ ------ + -------------------- + ---------------- + --------- + ------- + ----------- + ---------------------

| Id | User | Host | db | Command | Time | State | Info

+ ------ + -------------------- + ---------------- + --------- + ------- + ----------- + ---------------------

| 7028 | root | ucap-devgroup: 53396 | platform | Sleep | 19553 | NULL

| 8352 | root | ucap-devgroup: 54794 | platform | Sleep | 4245 | NULL

| 8353 | root | ucap-devgroup: 54795 | platform | Sleep | 3 | NULL

| 8358 | root | ucap-devgroup: 62605 | platform | query | 4156 | updating | update t_shop

The preceding figure shows the list of SQL statements currently being executed. Find the id of the statement with the largest resource consumption.

Run the kill command. The command format is as follows:

Kill id;

-Example:

Killed 8358

Kill.

Related Article

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.