How to check the MySQL lock via the MySQL show processlist command _mysql

Source: Internet
Author: User
Tags flush mysql manual
The output of the Processlist command shows which threads are running, which can help identify problematic query statements, and use this command in two ways.

1. Enter the Mysqladmin processlist into the Mysql/bin catalogue;

2. Start MySQL, enter show Processlist;

If you have super permissions, you can see all of the threads, otherwise you can only see the thread that you originated (this is the current corresponding MySQL account running thread).

The data forms are as follows (only three are intercepted):

Mysql> show Processlist;

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

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

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

|207|root |192.168.0.20:51718 |mytest | Sleep |        5 | | Null

|208|root |192.168.0.20:51719 |mytest | Sleep |        5 | | Null

|220|root |192.168.0.20:51731 |mytest | Query | 84 | Locked |

Select Bookname,culture,value,type from book where id=001

First of all, the meaning and use of the columns, the first column, ID, needless to say, a logo, you want to kill a statement when it is useful. The user column, which displays a single user, and if not root, this command displays only the SQL statements within your purview. The host column, which indicates which IP port the statement is issued from. Oh, can be used to track the user of the problem statement. DB column that shows which database the process is currently connected to. Command column, which displays commands for the execution of the current connection, generally hibernation (sleep), queries (query), connection (connect). Time column, which is the duration of this state, in seconds. State column, which shows the status of the SQL statement using the current connection, a very important column, followed by a description of all States, note that State is only one of the States in the execution of the statement, an SQL statement, a query as an example, may need to go through copying to TMP table, Sorting result,sending data can be completed, info column, display this SQL statement, because the length is limited, so long SQL statement is not complete, but an important basis for judging the problem statement.

The most critical of this command is the State column, which is listed in the following categories:

Checking table
Checking the datasheet (this is automatic).
Closing tables
The modified data in the table is being flushed to disk, and the tables that have been exhausted are being closed. This is a quick operation, and if not, you should make sure that the disk space is full or if the disk is in a heavy load.
Connect out
Replication is connecting to the primary server from the server.
Copying to TMP table on disk
Because the temporary result set is greater than tmp_table_size, the temporary table is being converted from memory storage to disk storage to save memory.
Creating TMP Table
A temporary table is being created to hold some of the query results.
deleting from Main Table
The server is performing the first part of a multiple table deletion and just deleted the first table.
deleting from reference tables
The server is performing the second part of a multiple table deletion and is deleting records from other tables.
Flushing tables
Executing flush tables, waiting for other threads to close the datasheet.
Killed
Sends a KILL request to a thread, the thread checks the kill flag bit and discards the next kill request. MySQL checks the kill flag bit in the main loop each time, but in some cases the thread may die a short time. If the line Chengcheng is locked by another thread, the kill request takes effect as soon as the lock is released.
Locked
was locked by another query.
Sending data
A record of a select query is being processed and the results are being sent to the client.
Sorting for group
Sorting GROUP BY.
Sorting for order
Ordering by is being sorted.
Opening tables
This process should be quick unless it is interfered by other factors. For example, a datasheet cannot be opened by another thread until the ALTER TABLE or LOCK table statement is done. Trying to open a table.
removing duplicates
A SELECT DISTINCT query is being executed, but MySQL cannot optimize those duplicate records in the previous phase. Therefore, MySQL needs to remove duplicate records again, and then send the results to the client.
Reopen table
A lock on a table is obtained, but the lock must be acquired after the table structure has been modified. The lock has been released, the datasheet is closed, and an attempt is being made to reopen the data table.
Repair by sorting
The repair instructions are being sorted to create an index.
Repair with Keycache
The repair instruction is using the index cache to create a new index one by one. It will be slower than repair by sorting.
Searching rows for update
The qualifying records are being identified for updating. It must be completed before update is required to modify the relevant records.
Sleeping
Waiting for client to send new request.
System Lock
Waiting to get an external system lock. If you are not currently running multiple mysqld servers requesting the same table at the same time, you can prevent external system locks by adding--skip-external-locking parameters.
Upgrading lock
Insert delayed is trying to get a lock table to insert a new record.
Updating
Searching for matching records and modifying them.
User Lock
Waiting for Get_lock ().
Waiting for tables
The thread is notified that the datasheet structure has been modified and that the data table needs to be reopened to obtain a new structure. Then, in order to be able to reopen the datasheet, you must wait until all other threads close the table. This notification is generated in the following situations: FLUSH TABLES tbl_name, Alter TABLE, RENAME table, REPAIR table, ANALYZE table, or optimize table.
Waiting for handler insert
Insert delayed has finished processing all pending inserts and is waiting for a new request.
Most of the state corresponds to a quick operation, as long as a thread remains in the same state for several seconds, then there may be a problem that needs to be checked.
There are other states that are not listed above, but most of them are only useful if they are looking at the server for errors.

The MySQL manual has all the status descriptions, linked as follows: http://dev.mysql.com/doc/refman/5.0/en/general-thread-states.html
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.