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

Source: Internet
Author: User

Enable mysql slow query log and run the mysqldumpslow command to check 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 = 1log-slow-queries =/usr/local/mysql/data/slow. loglog-queries-not-using-indexeslong_query_time = 1 # define 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 article mainly introduces two parameters-s and-t-s, which are sorting parameters. The options are: 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 show the first n records. Example: mysqldumpslow-s c-t 20 host-slow.logmysqldumpslow-s r-t 20 the preceding command shows the 20 most accessed SQL statements and the 20 most returned SQL record set. Mysqldumpslow-t 10-s t-g "left join" host-slow.log returns the first 10 SQL statements containing the left join according to 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.

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.