在mysql中设置通用查询日志

时间:2016-02-04 05:56:35

标签: mysql

我正在使用Windows 7和MySQL workbench 6.3

因此,当我开始设置日志文件时,我可以获取所有在MySQL数据库上被触发的查询。我陷入了困境。

C:\ Program Files \ MySQL1 \ MySQL Server 5.7之后,根据Google上的数百万篇文章,应该有任何my.ini文件。但我有my-default.ini。 :(

这是我的my-default.ini文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log=file.log
general-log=1
general-log-file=file.log

我刚刚添加了最后3行,以便我可以登录该文件。但是在bin中甚至没有任何文件file.log。

任何人都可以请帮我设置一下吗?提前致谢 !!

1 个答案:

答案 0 :(得分:0)

首先执行以下命令以启动常规日志 -

SET general_log=ON;

现在通过以下命令检查服务器正在写入的位置 -

SHOW VARIABLES LIKE 'general_log_file';

现在转到服务器,你可以阅读这些日志,在linux中你可以使用tail命令 -

tail -f /var/log/mysqd_query.log 

注意:此处路径和文件是var / log / mysqd_query.log