MySQL Execution state analysis show processlist

Source: Internet
Author: User
Tags mysql view

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).

[Plain]View PlainCopyprint?
  1. Mysql> Show full processlist;
  2. +---------+-------------+--------------------+----------------+-------------+-------+---------------------- -------------------------------------------------+-----------------------+  
  3. | id      | user         | Host                | db             | command      | Time  | State                                                                     | Info                   |  
  4. +---------+-------------+--------------------+----------------+-------------+-------+-------------------------- ---------------------------------------------+-----------------------+
  5. | 1056536 | Replication | 192.168.6.91:38417 | NULL | Binlog Dump | 33759 | Master has sent all binlog to slave; Waiting for Binlog to be updated | NULL |
  6. | 1107067 | miaohr      | 192.168.6.81:32024 |  NULL           | Query        |     0 | NULL                                                                      | show full processlist |  
  7. | 1107182 | miaohr      | 192.168.6.91:44217  | hr_db_business | Sleep       |      1 |                                                                           | NULL                   |  
  8. +---------+-------------+--------------------+----------------+-------------+-------+-------------------------- ---------------------------------------------+-----------------------+



This oneThe key in the command is the State column,MySQL is listed in the following main states:

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;

Performing State analysis

Sleep status

Usually indicates that the resource is not released, and if it is through a connection pool, the sleep state should be constant within a certain number of ranges

Actual combat example: due to the front-end data output (especially the output to the user terminal) did not close the database connection, resulting in a large number of sleep connections due to network connection speed, in the event of abnormal speed, the database too many connections hang dead.

Simple Interpretation, Data query and execution usually takes less than 0.01 seconds, and the network output usually takes 1 seconds or more, the original data connection can be released in 0.01 seconds, but because the front-end program does not perform close operation, direct output results, then the results are not displayed in front of the user table, the database connection has been maintained in the sleep state!

Waiting for net, reading from net, writing to net

Sometimes it doesn't hurt.

Quickly check the database to the front-end network connection status and traffic, as seen in large numbers

Case: Because of the plug-in program, the intranet database read a lot, the intranet use of the hundred trillion switch quickly full, resulting in a large number of connections blocked in waiting for net, the database connection too many crashes

Locked status

There is an update action lock

common use of innodb can be a good way to reduce the locked state of production, but remember that the update operation to correctly use the index, even if the low-frequency update operation can not be ignored . As shown in the example above affecting the result set.

In the age of MyISAM, Locked is a nightmare for many high-concurrency applications. So MySQL officials are starting to tend to recommend InnoDB.

Copy to TMP table

Indexes and existing structures cannot cover query criteria before a temporary table is established to meet the query requirements, resulting in a huge amount of horrible I/O pressure.

Very scary search statements can lead to such cases, if it is data analysis, or a midnight cycle of data cleanup tasks, occasionally appearing, may be allowed. The frequent occurrence must be optimized.

The Copy to TMP table is usually related to a linked table query, and it is recommended that you become accustomed to not using a table query.

Practical Examples:

U a Community database blocking, distress, check, its server exists multiple database applications and websites, one of the infrequently used small site database produced a horrible copy to TMP table operation, resulting in the entire hard disk I/O and CPU pressure overload. Kill the operation to recover everything.

Sending data

Sending data is not to be sent, not deceived by the name, this is the process of getting data from the physical disk, if you have more impact results set, then you need to extract data from different disk fragments,

Occasionally the state is connected without hindrance.

Back to the problem that affected the result set, in general, if the sending data connection is too large, the result set of the query is usually too big, that is, the index entry of the query is not optimized.

If a large number of similar SQL statements appear in the Show Proesslist list, and are all in the sending data state, optimize the query index, and remember to think about the ideas that affect the result set.

Storing result to query cache

In this state, if it occurs frequently, using set profiling analysis, if there is too much resource overhead in SQL overall overhead (that is, very small overhead, see scale), then query cache fragmentation is more

Use flush query cache to instantly clean up or make scheduled tasks

The Query cache parameter can be set appropriately, as appropriate.

Freeing items

Theoretically, this thing doesn't come in a lot. Occasionally, there is no obstruction.

If there is a large amount of memory, the hard disk may have been having problems. such as hard disk full or damaged.

When I/O pressure is too large, there may be a longer time for free items to execute.

Sorting for ...

Similar to sending data, the result set is too large, the sorting criteria are not indexed, they need to be sorted in memory, and even a temporary structure order needs to be created.

Other

There are many States, encountered, to check the information. Basically we encounter other states with less blocking, so don't care.

MySQL Execution state analysis show processlist

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.