I am using Mysql 5.6.12 under Wamp server environment. Now I want to log All queries into ".log" file, the queries which are running by PHP or from PHPMyAdmin, I want to log them...
3 Answers
[mysqld]
# Set Slow Query Log
long_query_time = 1
slow_query_log = 1
slow_query_log_file = /usr/log/slowquery.log
log_queries_not_using_indexes = 1
#Set General Log
general_log = on
general_log_file=/usr/log/general.log
Note that enabling general_log
on a production server has overhead you should avoid it. You can check problematic queries from slow log
.
-
1For me, I had to use "general_log = 1" instead of "general_log = on". Commented Dec 22, 2014 at 0:09
-
Worked on Wamp Server, using mysql 5.6.7. The only thing I had to change were the paths to tje files, in my case, C:\wamp\logs\mysql_query.log . Commented Mar 19, 2015 at 16:07
-
Why all these config values? Just
general_log
andgeneral_log_file
is enough.– laurentCommented Aug 25, 2017 at 13:12
Since this is the type of thing you probably only want to do temporarily, it may be useful to do this from the shell instead of via the config file:
> set global general_log_file = "/var/log/mysql/queries.log";
> set global general_log = "ON";
[wait some time, hit some pages, whatever]
> set global general_log = "OFF";
-
Note, that you need root privileges in the DB for these instructions, which is not a surprise. Commented Feb 13, 2023 at 2:49
Put these two lines in my.cnf.
[mysqld]
general_log = on
general_log_file=/users/ugrad/linehanp/mydb/logfile.txt
This will log all queries to the server, from any source, not just PHP/PHPMyAdmin.
Be careful though - enabling the general log can place a heavy load on your server. To be used sparingly for short periods/debugging only.
The documentation is available here. Fro there:
To disable or enable the general query log or change the log file name at runtime, use the global general_log and general_log_file system variables. Set general_log to 0 (or OFF) to disable the log or to 1 (or ON) to enable it. Set general_log_file to specify the name of the log file.
So,
general_log = on
and
general_log = 1
are synonyms!
-
For me, I had to use "general_log = 1" instead of "general_log = on". Commented Dec 22, 2014 at 0:09
-
-
Is this the
.my.cnf
file in a user's home directory? Or/etc/mysql/my.cnf
, which on my system is a symlink to/etc/mysql/mysql.cnf
?– FlimmCommented Aug 15, 2023 at 6:55 -
On my system (Ubuntu), the correct file to edit was
/etc/mysql/mysql.conf.d/mysqld.cnf
– FlimmCommented Aug 15, 2023 at 7:02