🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ mysql> show variables like "%long%"; //查看一下默认为慢查询的时间10秒 +--------------------------------------------------------+----------+ | Variable_name | Value | +--------------------------------------------------------+----------+ | long_query_time | 1.000000 | | performance_schema_events_stages_history_long_size | 1000 | | performance_schema_events_statements_history_long_size | 1000 | | performance_schema_events_waits_history_long_size | 1000 | +--------------------------------------------------------+----------+ 4 rows in set (0.00 sec) ~~~ ~~~ mysql> set global long_query_time=2; //设置成2秒,加上global,下次进mysql已然生效 Query OK, 0 rows affected (0.00 sec) ~~~ ~~~ mysql> show variables like "%slow%"; //查看一下慢查询是不是已经开启 +---------------------------+-----------------------------------+ | Variable_name | Value | +---------------------------+-----------------------------------+ | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /var/lib/mysql/localhost-slow.log | +---------------------------+-----------------------------------+ 5 rows in set (0.00 sec) ~~~ ~~~ mysql> set slow_query_log='ON'; //加上global,不然会报错的。 ERROR 1229 (HY000): Variable 'slow_query_log' is a GLOBAL variable and should be set with SET GLOBAL mysql> set global slow_query_log='ON'; //启用慢查询 Query OK, 0 rows affected (0.28 sec) ~~~ ~~~ mysql> show variables like "%slow%"; //查看是否已经开启 +---------------------------+-----------------------------------+ | Variable_name | Value | +---------------------------+-----------------------------------+ | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /var/lib/mysql/localhost-slow.log | +---------------------------+-----------------------------------+ 5 rows in set (0.00 sec) ~~~ ~~~ set global general_log='ON'; //开启执行sql日志 show variables like "%log%"; //查看日志是否开启 ~~~