GLOBAL variable and should be set with SET GLOBAL

方法1,用命令开启慢查询

查看复制打印?
1.mysql> show variables like "%long%";         //查看一下默认为慢查询的时间10秒  
2.+-----------------+-----------+  
3.| Variable_name   | Value     |  
4.+-----------------+-----------+  
5.| long_query_time | 10.000000 |  
6.+-----------------+-----------+  
7.1 row in set (0.00 sec)  
8. 
9.mysql> set global long_query_time=2;          //设置成2秒,加上global,下次进mysql已然生效  
10.Query OK, 0 rows affected (0.00 sec)  
11. 
12.mysql> show variables like "%slow%";          //查看一下慢查询是不是已经开启  
13.+---------------------+---------------------------------+  
14.| Variable_name       | Value                           |  
15.+---------------------+---------------------------------+  
16.| log_slow_queries    | OFF                             |  
17.| slow_launch_time    | 2                               |  
18.| slow_query_log      | OFF                             |  
19.| slow_query_log_file | /usr/local/mysql/mysql-slow.log |  
20.+---------------------+---------------------------------+  
21.4 rows in set (0.00 sec)  

22. set character_set_results=utf8;

23.mysql> set slow_query_log='ON';                        //加上global,不然会报错的。  
24.ERROR 1229 (HY000): Variable 'slow_query_log' is a GLOBAL variable and should be set with SET GLOBAL  
25.mysql> set global slow_query_log='ON';            //启用慢查询  
26.Query OK, 0 rows affected (0.28 sec)  

27. 
28.mysql> show variables like "%slow%";              //查看是否已经开启  
29.+---------------------+---------------------------------+  
30.| Variable_name       | Value                           |  
31.+---------------------+---------------------------------+  
32.| log_slow_queries    | ON                              |  
33.| slow_launch_time    | 2                               |  
34.| slow_query_log      | ON                              |  
35.| slow_query_log_file | /usr/local/mysql/mysql-slow.log |  
36.+---------------------+---------------------------------+  
37.4 rows in set (0.00 sec) 
mysql> show variables like "%long%";         //查看一下默认为慢查询的时间10秒
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row 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_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)

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_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) 

你可能感兴趣的:(MYSQL)