Enable mysql slow query log and run the mysqldumpslow command to View _ MySQL

Source: Internet
Author: User
Tags mysql slow query log
Enable mysql slow query log and run mysqldumpslow to view mysqldump

BitsCN.com

Enable mysql slow query logs and run the mysqldumpslow command to view the logs.

The mysql server has a function to detect which SQL statement query is slow, that is, slow query slowlog. now we will introduce how to enable this function.

Add the following code under [mysqld:

Long_query_time = 1

Log-slow-queries =/usr/local/mysql/data/slow. log

Log-queries-not-using-indexes

Long_query_time = 1 # defines the Slow_queries variable for queries that exceed 1 second.

Log-slow-queries =/usr/local/mysql/data/slow. log # defines the log path for slow query.

Log-queries-not-using-indexes # queries without indexes are recorded in slow query logs (optional ).

Mysql comes with mysqldumpslow, a tool for viewing slow logs.

Run mysqldumpslow -- h to view help information.

This section describes two parameters:-s and-t.

-S: this is the sorting parameter and can be selected as follows:

Al: average lock time

Ar: average number of returned Records

At: average query time

C: Count

L: lock time

R: return record

T: query time

-T n: the first n records are displayed.

Instance:

Mysqldumpslow-s c-t 20 host-slow.log

Mysqldumpslow-s r-t 20 host-slow.log

The preceding command shows the 20 most frequently accessed SQL statements and the 20 most returned SQL statements in the record set.

Mysqldumpslow-t 10-s t-g left join host-slow.log

Return the first 10 SQL statements containing the left join according to the time.

With this tool, you can find out which SQL statements are performance bottlenecks and optimize them, such as adding indexes and implementing the application.

BitsCN.com

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.