Mysql (slow-query) quick method for enabling slow log query _ MySQL

Source: Internet
Author: User
Mysql (slow-query) quick method for enabling slow log query bitsCN.com

How to quickly enable slow log query in mysql (slow-query)

Mysql has a function to log down and run slow SQL statements. by default, this log does not exist.

Open my. ini, find [mysql], and add

Long_query_time = 2

Log-slow-queries = D:/mysql/logs/slow. log # set to write the log there. it can be blank and the system will
A default file

# Log-slow-queries =/var/youpath/slow. log host_name-slow.log in linux

Log-queries-not-using-indexes

Long_query_time indicates how long the SQL statement is executed (in seconds) and is recorded. here, it is set to 2 seconds.

Log-slow-queries sets the location of the log, which can be null. The system will give a default file
Host_name-slow.log, the generated log is under the mysql data directory

Log-queries-not-using-indexes is a literal query that does not use an index.

The following describes common mysqldumpslow parameters. you can use mysqldumpslow-help to query them in detail.

-S indicates the sorting method. c, t, l, and r indicate the number of records, time, query time, and returned
The number of records is sorted (from large to small). ac, at, al, and ar indicate the corresponding flashback.

-T indicates the top n, that is, the number of previous data records returned.

-G, followed by a regular expression matching mode, which is case insensitive.

The next step is to use mysql's built-in slow query tool mysqldumpslow for analysis (in the bin directory of mysql

), My log file name here is host-slow.log.

List the 10 SQL statements with the maximum number of records

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

List up to 10 SQL statements that return a record set

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

Return the first 10 SQL statements containing the left join by time

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

The mysqldumpslow command can be used to obtain various query statements that we need very clearly.
The monitoring, analysis, and optimization of query statements are of great help.

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.