log表不能修改成innodb引擎

MySQL.slow_log 获取慢查询日志很慢,该表是csv表,没有索引。
想添加索引来加速访问,而csv引擎不能添加索引(csv引擎存储是以逗号分割的文本来存储的),只能改存储引擎来添加索引了

mysql.slow_log表能改成myisam,不能改成innodb

MySQL slow_log表不能修改成innodb引擎

mysql> set global slow_query_log=off; Query OK, 0 rows affected (0.00 sec) mysql> alter table mysql.slow_log engine=innodb; ERROR 1579 (HY000): This storage engine cannot be used for log tables" mysql> alter table mysql.slow_log engine=myisam; Query OK, 33760 rows affected (0.37 sec) Records: 33760 Duplicates: 0 Warnings: 0

mysql.general_log也不能改成innodb

mysql> alter table mysql.general_log engine=myisam; Query OK, 242956 rows affected (2.41 sec) Records: 242956 Duplicates: 0 Warnings: 0 mysql> alter table mysql.general_log engine=innodb; ERROR 1579 (HY000): This storage engine cannot be used for log tables"

官方文档

MySQL slow_log表不能修改成innodb引擎

官方文档说明,日志表只支持csv引擎和myisam引擎。
为什么不支持innodb引擎并未说明

基于什么来考虑不支持innodb表的了?
像朋友请教了下

估计是日志表 这种引擎会耗费大量的redo, undo 资源吧

这是没有必要的。。。这些数据不重要。。

更改日志表存储引擎并添加索引
mysql.general_log表

set sql_log_bin=0; SET @old_log_state = @@global.general_log; SET GLOBAL general_log = 'OFF'; ALTER TABLE mysql.general_log ENGINE = MyISAM; SET GLOBAL general_log = @old_log_state;

mysql.slow_log表

set sql_log_bin=0; set @old_slow_log_state=@@global.slow_query_log; set global slow_query_log='OFF'; ALTER TABLE mysql.slow_log ENGINE = MyISAM; alter table mysql.slow_log add index idx_query_time(query_time); set global slow_query_log=@old_slow_log_state;

注意问题

更改日志表的存储引擎需要先关闭日志表,还需要不记录会话的binlog日志
不然,主从复制中,从库会出现sql线程错误

LAST_ERROR_MESSAGE: Worker 1 failed executing transaction '5a459629-1e13-11e9-a99d-74eacb7427c5:377210591' at master log mysql-bin.001278, end_log_pos 40623782; Error 'You cannot 'ALTER' a log table if logging is enabled' on query. Default database: ''. Query: 'ALTER TABLE mysql.slow_log ENGINE = MyISAM'

归档日志表
归档mysql.general_log表

USE mysql; DROP TABLE IF EXISTS general_log2; CREATE TABLE general_log2 LIKE general_log; RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;

归档mysql.slow_log表

USE mysql; DROP TABLE IF EXISTS slow_log2; CREATE TABLE slow_log2 LIKE slow_log; RENAME TABLE slow_log TO slow_log_backup, slow_log2 TO slow_log;

参考

Selecting General Query Log and Slow Query Log Output Destinations

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b2765c7ab84102034005a2321ddf32a0.html