Home  >  Article  >  Database  >  How to enable slow query log in mysql command line

How to enable slow query log in mysql command line

王林
王林Original
2020-09-30 09:28:341897browse

Mysql command line method to enable slow query log: Execute the [set global slow_query_log='ON';] statement to enable it. You can check whether the slow query log is enabled by executing the [show variables like "%slow%";] statement.

How to enable slow query log in mysql command line

Specific method:

(Recommended tutorial: mysql tutorial)

Check the default slow speed The query time is 10 seconds

mysql> show variables like "%long%";         
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)

Set to 3 seconds, add global, exit and re-enter to take effect

mysql> set global long_query_time=3;         
Query OK, 0 rows affected (0.00 sec)

Check whether slow query has been enabled

mysql> show variables like "%slow%";         
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| log_slow_queries    | OFF                             |
| slow_launch_time    | 2                               |
| slow_query_log      | OFF                             |
| slow_query_log_file | /usr/local/mysql/mysql-slow.log |
+---------------------+---------------------------------+
4 rows in set (0.00 sec)

Enable slow query

mysql> set global slow_query_log='ON';          
Query OK, 0 rows affected (0.28 sec)

Check whether it has been enabled

mysql> show variables like "%slow%";             
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| log_slow_queries    | ON                              |
| slow_launch_time    | 2                               |
| slow_query_log      | ON                              |
| slow_query_log_file | /usr/local/mysql/mysql-slow.log |
+---------------------+---------------------------------+
4 rows in set (0.00 sec)

Related recommendations: php training

The above is the detailed content of How to enable slow query log in mysql command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn