How to find slow SQL statements in mysql

Source: Internet
Author: User
Tags mysql update

How can I find slow SQL statements in mysql? This may be a problem for many people. The following describes how to find slow SQL statements in mysql for your reference.

When Mysql is started, add the -- log-slow-queries parameter to record the SQL statements whose execution time exceeds long_query_time seconds.

MySQL comes with the slow log analysis tool mysqldumpslow.
Slow log is a file written by MySQL based on the execution time of SQL statements. It is used to analyze slow statements.

You only need to configure in the my. cnf file:
Log-slow-queries = [slow_query_log_filename]
You can record the SQL statement that exceeds the default 10 s execution time.
To modify the default settings, you can add:
Long_query_time = 5
Set to 5S.

/Usr/sbin/mysqld -- basedir =/usr -- datadir =/var/lib/mysql -- user = mysql -- pid-file =/var/run/mysqld. pid -- skip-locking -- port = 3306 -- socket =/var/run/mysqld. sock -- log-slow-queries =/var/log/mysql/slow. log

Explain to understand the SQL Execution status.
Explain select * from wp_posts \ G;

Explain shows how mysql uses indexes to process select statements and connect tables. It can help you select better indexes and write more optimized query statements.

You can add the explain statement before the select statement:

Example: explain select surname, first_name form a, B where a. id = B. id

The preceding describes how to find slow SQL statements in mysql.

How to use mysql UPDATE statements

Mysql inserts an instance of the Clob Field

Default length of common MySql Fields

MySQL inserts multiple records using INSERT

General INSERT usage in MySQL

Related Article

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.