bitscn.com
mysql命令行开启slow.log失败解决
有需要去看下slow.log,但是发现slow.log好久没写了。
看了下服务器设置:
root@(none) 01:13:41>show global variables like '%slow%';
+---------------------+-------------------------+
| variable_name | value |
+---------------------+-------------------------+
| log_slow_queries | off |
| slow_launch_time | 2 |
| slow_query_log | off |
| slow_query_log_file | /u01/mysql/log/slow.log |
+---------------------+-------------------------+
4 rows in set (0.00 sec)
关闭的,于是开启,竟然报错。
root@(none) 01:14:27>set global slow_query_log=1;
error 1146 (42s02): table 'mysql.slow_log' doesn't exist
发现mysql.slow_log表不存在,desc了下,确实不存在。该表,是当开启参数log_output设置为table的时候,slow.log会记录到这个表里面,但是由于记录该表会对性能有影响,所以一般都是记录到file里面,然后再用脚本来处理。
那么难道写file也必须该表存在吗?
我手动把这个表建上。
// 不让该操作写到binlog中
set session sql_log_bin=0;
use mysql
create table `slow_log` (
`start_time` timestamp not null default current_timestamp on update current_timestamp,
`user_host` mediumtext not null,
`query_time` time not null,
`lock_time` time not null,
`rows_sent` int(11) not null,
`rows_examined` int(11) not null,
`db` varchar(512) not null,
`last_insert_id` int(11) not null,
`insert_id` int(11) not null,
`server_id` int(10) unsigned not null,
`sql_text` mediumtext not null
) engine=csv default charset=utf8 comment='slow log'
然后:
root@mysql 01:34:02>set global slow_query_log=1;
query ok, 0 rows affected (0.00 sec)
设置ok,来测试下:
root@(none) 01:35:40>select sleep(2);
+----------+
| sleep(2) |
+----------+
| 0 |
+----------+
1 row in set (2.00 sec)
slow.log里面:
time: 130124 13:35:52
# user@host: root[root] @ localhost []
# query_time: 2.002410 lock_time: 0.000000 rows_sent: 1 rows_examined: 0
set timestamp=1359005752;
select sleep(2);
设置成功。
总结:
mysql.slow_log表还是必须的,没有这个表slow log 也不能输出到file。
bitscn.com