当前位置:  首页  >  PHP教程  >  PHP 应用  >  常见问题

ERROR1146(42S02):Table'mysql.slow_log'doesn'texist

ERROR1146(42S02):Table

ERROR 1146 (42S02): Table

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

竟然是空的,为什么?

吐了个 "CAO" !
扫码关注 PHP1 官方微信号
PHP1.CN | 中国最专业的PHP中文社区 | PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | PHP问答
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有