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.
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!