开发者

Enabling query log in MySQL 5 on Windows 7

How do I do it? I want all 开发者_Go百科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.


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.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]

and u will find Program Data\mysql\MySQL Server 5.1\data or I really recommand that using everything to search "filename.log "

in cmd

 net stop mysql

 net start mysql


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

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

# 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

# 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>


For slow query log add to 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜