慢日志之二:ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist,分析诊断工具之四

去查看最新的slow log,发现没有最新的记录,上去检查slow log是否开启了。


MySQL> show variables like '%slow%';

+---------------------+------------------------------------------+
| Variable_name       | Value                                    |
+---------------------+------------------------------------------+
| log_slow_queries    | OFF                                      |
| slow_launch_time    | 2                                        |
| slow_query_log      | OFF                                      |
| slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
+---------------------+------------------------------------------+
4 rows in set (0.00 sec)

看到OFF,果然关闭了,立即打开。


mysql> set global slow_query_log='on';
ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist
mysql> 
mysql> 
mysql> set global slow_query_log=1;
ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist
mysql> 
mysql> exit

Bye


报错了,去mysql库check下,有无这个表:

mysql> use mysql
Database changed
mysql> desc slow_log;
ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist


mysql.slow_log表还是必须的,没有这个表slow log 也不能输出到FILE。该表,是当开启参数log_output设置为table的时候,slow.log会记录到这个表里面,但是由于记录该表会对性能有影响,所以一般都是记录到FILE里面,然后再用脚本来处理。现在报错那就临时创建下这个表试试看,不过记得关闭写入二进制,因为是双主嘛:

mysql> set session sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)


mysql> use mysql
Database changed


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='just only a slow log';
Query OK, 0 rows affected (0.02 sec)


mysql> 
mysql> 



然后再去开启slow log 日志

mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.00 sec)


mysql> 


mysql> 
mysql> 
mysql> select sleep(10),1 as a;
+-----------+---+
| sleep(10) | a |
+-----------+---+
|         0 | 1 |
+-----------+---+
1 row in set (10.00 sec)


mysql> 


然后去check下这个慢查询sql是否写入slow log了

ll slow_queries_3306.log

-rw-rw---- 1 mysql mysql       0 Feb 10 04:10 slow_queries_3306.log

posted on 2013-09-23 09:17  duanxz  阅读(912)  评论(0编辑  收藏  举报