我启用了记录using:
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
所有已执行的查询都记录到mysql.general_log
表。没关系。
然后表变大了,我想删除表中的所有记录。我执行了:
DELETE FROM general_log
但是这导致了一个错误,说我无法锁定日志表。因此,在禁用日志记录后删除了表:
SET GLOBAL general_log = 'OFF';
DROP TABLE general_log;
我希望再次启用日志记录会创建表,但我无法启用它。当我执行此操作时:
SET GLOBAL general_log = 'ON';
它给出了这个错误:
表'mysql.general_log'不存在
mysql.general_log
? mysql.general_log
? 答案 0 :(得分:19)
USE mysql;
CREATE TABLE IF NOT EXISTS `general_log` (
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`command_type` varchar(64) NOT NULL,
`argument` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log';
TRUNCATE table mysql.general_log;
答案 1 :(得分:5)
1:
USE mysql;
CREATE TABLE `general_log` (
`event_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_host` MEDIUMTEXT NOT NULL,
`thread_id` INT(11) NOT NULL,
`server_id` INT(10) UNSIGNED NOT NULL,
`command_type` VARCHAR(64) NOT NULL,
`argument` MEDIUMTEXT NOT NULL
)
COMMENT='General log'
COLLATE='utf8_general_ci'
ENGINE=CSV;
2:
TRUNCATE mysql.general_log;
答案 2 :(得分:4)
这是更新版本,2012年答案不再适用:
CREATE TABLE mysql.general_log (
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`thread_id` bigint(21) unsigned NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`command_type` varchar(64) NOT NULL,
`argument` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'
答案 3 :(得分:3)
Ok, having first hand experience, this is what worked for me, if your table gets corrupted by any reason whatsoever, works with MySQL 5.6.11
var noCamel = str.replace(/(\B[A-Z])/g, ' $1');
答案 4 :(得分:3)
我也放弃了mysql.general_log
表,但其他答案对我没有帮助。
然后,我注意到有关表结构的错误导致它在MySQL 5.7.18
上有点不同,所以我改变了一些字段,现在它可以正常工作。
如果有人需要它:
CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` bigint(21) unsigned NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`command_type` varchar(64) NOT NULL,
`argument` mediumblob
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='General log'
答案 5 :(得分:0)
在MySQL 8.0.17中重新创建表:
use mysql;
CREATE TABLE general_log(
event_time timestamp(6) NOT NULL ,
user_host mediumtext NOT NULL,
thread_id bigint(21) unsigned NOT NULL,
server_id int unsigned NOT NULL,
command_type varchar(64) NOT NULL,
argument mediumblob NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log';