在 Windows 7 上的 MySQL 5 中启用查询日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4731228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enabling query log in MySQL 5 on Windows 7
提问by A-OK
How do I do it? I want all queries logged, don't care about the performance hit. The docs say I need to start mysqld with -l but I can't change the parameters when editing this service.
我该怎么做?我希望记录所有查询,不关心性能影响。文档说我需要使用 -l 启动 mysqld,但是在编辑此服务时我无法更改参数。
采纳答案by Marc B
You can set the option in the my.cnf
(possibly my.ini
) file, wherever it happens to get installed on your machine. Command line arguments are more for a one-time override, while the my.cnf is for permanent settings.
您可以在my.cnf
(可能my.ini
)文件中设置该选项,无论它安装在您机器上的任何位置。命令行参数更多用于一次性覆盖,而 my.cnf 用于永久设置。
回答by phil
my.ini
\# SERVER SECTION
\# ----------------------------------------------------------------------
\# The following options will be read by the MySQL Server. Make sure that
\# you have installed the server correctly (see above) so it reads this
\# file.
[mysqld]
add
添加
log=filename.log
or u can set a Absolute Path of ,please new the new file ;
或者你可以设置一个绝对路径,请新建新文件;
below [mysqld]
下面[mysqld]
and u will find Program Data\mysql\MySQL Server 5.1\data or I really recommand that using everythingto search "filename.log "
你会发现 Program Data\mysql\MySQL Server 5.1\data 或者我真的建议使用一切来搜索“filename.log”
in cmd
在cmd 中
net stop mysql
net start mysql
回答by N?s????? ?
The slow query log will be already enabled in the version MySQL Server 5.7 and above, and by default it is set to 10 seconds
MySQL Server 5.7及以上版本已经开启慢查询日志,默认设置为10秒
To test it in command prompt try this:
要在命令提示符下测试它,请尝试以下操作:
mysql -u root -p
SELECT SLEEP(11);
Navigate to %PROGRAMDATA%\MySQL\<MySQL Server Version>\Data\*-*-slow.log
导航 %PROGRAMDATA%\MySQL\<MySQL Server Version>\Data\*-*-slow.log
# Time: 2018-05-14T18:17:01.863030Z
# User@Host: root[root] @ localhost [127.0.0.1] Id: 4
# Query_time: 10.999955 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1526321821;
SELECT SLEEP(11);
If not enabled navigate to
如果未启用导航到
%PROGRAMDATA%\MySQL\<MySQL Server Version>\my.ini
and paste the below lines
%PROGRAMDATA%\MySQL\<MySQL Server Version>\my.ini
并粘贴以下几行
# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="DESKTOP-XYZ123.log"
slow-query-log=1
slow_query_log_file="DESKTOP-XYZ123-slow.log"
long_query_time=10
From command prompt type:
从命令提示符键入:
net stop <MySQL instance Name>
net start <MySQL instance Name>
回答by quAnton
For slow query log add to my.ini
对于慢查询日志添加到 my.ini
[mysqld]
# Enable slow query log
slow-query-log
# Name of slow query log file
slow_query_log_file = slow-query.log
# Log all queries that have taken more than long_query_time seconds to execute to file
long_query_time = 3