无法在 wamp 运行 mysql 5.6 上启用 MySql 一般查询日志文件

can't enable MySql general query log file on wamp running mysql 5.6

我在 WAMP 中激活通用查询日志文件时遇到问题我查看了很多线程,但似乎无法让它写入日志。

我已经尝试了好的查询和坏的查询来尝试触发日志。

有什么建议吗?

这是我的my.ini

# The MySQL server
[wampmysqld]
port        = 3306
socket      = /tmp/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir=c:/wamp/bin/mysql/mysql5.6.17
log-error=c:/wamp/logs/mysql.log
datadir=c:/wamp/bin/mysql/mysql5.6.17/data
log-output = FILE
general-log = 1
general_log_file=C:/wamp/logs/general-query.log

您在 general-log 中有错字。应该是general_log

然后 mysql 重启。

并检查你的变量,重启后如

select @@general_log; -- 0 (that means OFF). 1 is ON.
select @@general_log_file; -- GUYSMILEY.log
select @@datadir; -- C:\ProgramData\MySQL\MySQL Server 5.6\Data\
select @@version; -- 5.6.31-log

要设置动态变量以覆盖 cnf 或 ini 文件设置,请执行类似以下操作:

set GLOBAL general_log=1;

记住是datadir,不是basedir。您可能需要在 Windows 上打开查看隐藏文件夹才能看到 \ProgramData 如果那是您 datadir 点。

最后,您不需要用错误 sql 语句来欺骗它。通用查询日志适用于所有查询。

有关它的屏幕截图,请参阅 This Answer。请记住,它适用于所有查询。因此,将其关闭、复制、删除、重新打开,它会重新生成。不要忘记在生产中激活通用日志会降低性能。

此外,请参阅来自 Gryphius 的 answer

编辑(根据您在评论中的问题)。

如果未在 cnf 或 ini 设置中反映,对动态变量的更改是短暂的。意思是,它们会在 mysql 重新启动时重置。

我不知道关闭错误日志记录的方法,我也可能不想这样做。错误很少见,了解它们非常重要。所以下面应该满足你 4 个好奇心中的 3 个:

show variables like '%error%';
show variables like '%slow%';

log_error -- string for filename

slow_query_log -- set to 'ON' or 1, 'OFF' or 0
slow_query_log_file; --- string for filename

那么总有show variables;

有关 slow query log. If you set the long_query_time high enough, it will effectively filter out more noise. It is in seconds, from 0 to 10. And a Percona 文章的更多信息,但已过时。

select @@long_query_time;
+-------------------+
| @@long_query_time |
+-------------------+
|         10.000000 |
+-------------------+

请注意,我似乎无法使用 SET GLOBAL stmt 设置以上内容。所以它似乎只是 cnf 或 ini 文件的设置。但您可以执行以下操作:

select @@slow_query_log; -- to see current value
select @@slow_query_log_file; -- to see current value (file in datadir)
select @@datadir; -- to see current value

set global slow_query_log=0; -- Turn Off
-- make a backup of it with a move and rename (See Note1) to a folder below datadir
set global slow_query_log=1; -- Turn it back On (new empty file is created)

Note1:复制的文件图像,在上面的 Note1 时间点重命名。 Image Here.