The MySQL database looks for slow execution SQL statements

Source: Internet
Author: User

When you start MySQL, add the parameter--log-slow-queries to log the SQL that executes longer than long_query_time seconds:

/usr/sbin/mysqld--basedir=/usr--datadir=/var/lib/mysql

--user=mysql--pid-file=/var/run/mysqld/mysqld.pid

--skip-locking--port=3306--socket=/var/run/mysqld/mysqld.sock--log-slow-

Queries=/var/log/mysql/slow.log

Explain to understand the state of SQL execution.

Explain select * from WP_POSTSG;

Use show status like "handler_read%"; To understand the effect of the index.

A high Handler_read_key value indicates a good index effect, and a high Handler_read_rnd_next value indicates inefficient indexing.

Use show processlist to view the current running state.

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

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.