Home > Database > Mysql Tutorial > body text

How to enable slow query log in mysql command line

王林
Release: 2020-09-30 09:28:34
Original
1890 people have browsed it

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)
Copy after login

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)
Copy after login

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)
Copy after login

Enable slow query

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

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template