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