在 MySQL 中设置常规查询日志



我正在使用Windows 7和MySQL工作台6.3

因此,当我开始设置日志文件时,我可以在其中获取在MySQL数据库上触发的所有查询。我卡得很糟糕。

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

这是我的默认.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 行,以便我可以登录该文件..但是我什么也没得到,甚至没有文件文件.log在垃圾箱中。

任何人都可以帮我设置这个吗?提前感谢!!

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

SET general_log=ON;

现在通过以下命令检查您的服务器在哪里写入它们-

SHOW VARIABLES LIKE 'general_log_file';

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

tail -f /var/log/mysqd_query.log 

注意:这里的路径和文件是var/log/mysqd_query.log

最新更新