ITPub博客

首页 > 数据库 > MySQL > ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist

ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist

原创 MySQL 作者:mchdba 时间:2014-03-18 12:07:11 0 删除 编辑

去查看最新的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


竟然是空的,为什么?

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26230597/viewspace-1123960/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Happy is the man who is living by his hobby.

注册时间:2011-09-05

  • 博文量
    147
  • 访问量
    3759880