MySQL show processlist show MySQL query process

Source: Internet
Author: User
Tags mysql query mysql view

1. Enter Mysqladmin processlist into the Mysql/bin directory;
2. Start MySQL and enter show Processlist;
If you have SUPER privileges, you can see all the threads, otherwise you will only see the thread that you initiated (this is the thread that the current MySQL account is running on).
The data is obtained in the form of the following (only three interception):
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 purpose of each column, the first column, ID, needless to say, an identity, you want to kill a statement when it is useful. The user column shows the single-user, if not root, this command displays only the SQL statements within the scope of your permission. The host column that shows which IP port this statement was issued from. Oh, can be used to track the problem of the user statement. The DB column that shows which database the process is currently connected to. Command column, which displays the execution commands for the current connection, typically sleep (sleep), 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, the very important column, followed by a description of all States, note that State is only one of the states in the statement execution, an SQL statement that has been queried as an example, may need to go through copying to TMP table, Sorting result,sending data and other status can be completed, info column, display this SQL statement

If you perform additions or deletions to a large table or execute a complex SQL query that causes the MySQL thread to hang. Use this command to find out which SQL hangs, use Kill to get him k off.

How to use the KILL command

Kill PID

As in the example above, we want to kill a thread with ID 207 to execute

Kill 207.

MySQL show processlist command detailed


Show Processlist shows which threads are running. You can also use the Mysqladmin processlist statement to get this information. If you have super privileges, you can see all the threads. Otherwise, you can only see your own thread (that is, the thread associated with the MySQL account you are using). See section 13.5, 5.3, "kill syntax". If you do not use the full keyword, only the first 100 characters of each query are displayed.

This statement reports the host name of the TCP/IP connection (in host_name:client_port format) to easily determine which client is doing what.

This statement is useful if you get the "Too many connections" error message and want to know what is happening. MySQL keeps an extra connection for an account with super privileges to ensure that the administrator is able to connect and check the system at any time (assuming you do not give this permission to all users).

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

Checking Table
Checking the data table (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 confirm that the disk space is full or that the disk is under heavy load.
Connect out
Replication from the server is connecting to the primary server.
Copying to TMP table on disk
Because the temporary result set is larger than tmp_table_size, the temporary table is being converted from memory storage to disk storage to save memory.
Creating tmp table
Creating temporary tables to hold partial query results.
deleting from Main Table
The server is performing the first part of a multi-table delete and has just deleted the first table.
Deleting from reference tables
The server is performing the second part of a multi-table delete and is deleting records from other tables.
Flushing tables
Executing flush TABLES, waiting for other threads to close the data table.
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 each of the main loops, but in some cases the thread may die in a short period of time. If the line regulation regulation is locked by another thread, the kill request will take effect as soon as the lock is released.
Locked
Locked by another query.
Sending Data
The record for the select query is being processed, and the results are being sent to the client.
Sorting for Group
Sorting is being done for group by.
Sorting for order
The order by is being sorted.
Opening Tables
The process should be quick, unless other factors interfere with it. For example, a data table cannot be opened by another thread until the row of the ALTER TABLE or LOCK TABLE statement is complete. Attempting to open a table.
Removing duplicates
A query that is executing a SELECT distinct method is being executed, but MySQL cannot optimize those duplicate records in the previous phase. Therefore, MySQL needs to remove the duplicate records again, and then send the results to the client.
Reopen Table
A lock on a table is obtained, but it must be changed after the table structure has been modified. The lock has been released, the data table is closed, and the data table is being tried again.
Repair by sorting
Repair instructions are being sorted to create an index.
Repair with Keycache
The repair instructions are 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 told to find out to prepare for the update. It must be completed before the update is about to modify the related records.
Sleeping
Waiting for the client to send a new request.
System Lock
Is 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 suppress the external system lock by increasing the--skip-external-locking parameter.
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 data table structure has been modified and the data table needs to be reopened to obtain a new structure. Then, to be able to reopen the data table, you must wait until all other threads close the table. This notification is generated in the following cases: FLUSH TABLES tbl_name, ALTER table, RENAME table, REPAIR table, ANALYZE table, or optimize table.
waiting for handler insert
Insert delayed has processed all pending insertions and is waiting for a new request.
Most of the state corresponds to a fast operation, so long as one thread remains in the same state for several seconds, a problem may occur and need to be checked.
There are other states that are not listed above, but most of them are only useful to see if there is an error in the server.

MySQL view current number of connections

Command: Show Processlist;
If it is the root account, you can see the current connection for all users. If you are a normal account, you can only see the connection you are occupying.
Show Processlist; only the first 100 are listed, please use show full processlist if you want to list them all.
Mysql> show Processlist;

Command: Show status;

Aborted_clients the number of connections that have been discarded because the client did not properly close the connection already dead.
Aborted_connects the number of times the connection to the MySQL server has failed.
Connections the number of attempts to connect to the MySQL server.
Created_tmp_tables the number of suppressed temporary tables that have been created when the statement is executed.
Delayed_insert_threads the number of deferred plug-in processor threads being used.
Delayed_writes the number of rows written with the insert Delayed.
Delayed_errors the number of rows written with insert Delayed for some errors (possibly repeating key values).
Flush_commands the number of times the flush command was executed.
Handler_delete the number of times a row was requested to be deleted from a table.
The number of times the Handler_read_first request reads the first row in the table.
The Handler_read_key requests a number based on the key read line.
The number of times a handler_read_next request reads into a row based on one key.
The number of times a HANDLER_READ_RND request reads into a row based on a fixed position.
Handler_update the number of times a row in the table was requested to be updated.
The number of times the Handler_write request inserts a row into the table.
key_blocks_used the number of blocks used for the keyword cache.
Key_read_requests the number of times a key value was requested to be read from the cache.
Key_reads the number of times a key value has been physically read from disk.
Key_write_requests requests a keyword block to be written to the cache count.
Key_writes the number of times a key-value block is physically written to disk.
Max_used_connections the maximum number of connections that are used at the same time.
Not_flushed_key_blocks a key block that has been changed in the key cache but has not been emptied to disk.
Not_flushed_delayed_rows the number of rows waiting to be written in the Insert delay queue.
Open_tables the number of open tables.
Open_files the number of open files.
Open_streams Number of open streams (primarily for log records)
Opened_tables the number of tables that have been opened.
Questions the number of queries destined for the server.
Slow_queries the number of queries that will take more than long_query_time time.
threads_connected the number of connections currently open.
Threads_running the number of threads that are not sleeping.
Uptime How many seconds the server has worked.

MySQL show processlist show MySQL query process

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.