Is it possible for me to turn on audit logging on my mysql database?
I basically want to monitor all queries for an hour, and dump the log to a file.
Is it possible for me to turn on audit logging on my mysql database?
I basically want to monitor all queries for an hour, and dump the log to a file.
Enable the log for table
View log by select query
Besides what I came across here, running the following was the simplest way to dump queries to a log file without restarting
can be turned off with
Top answer doesn't work in mysql 5.6+. Use this instead:
in your my.cnf / my.ini file
Ubuntu/Debian: /etc/mysql/my.cnf
Windows: c:\ProgramData\MySQL\MySQL Server 5.x
wamp: c:\wamp\bin\mysql\mysqlx.y.z\my.ini
xampp: c:\xampp\mysql\bin\my.ini.
Start mysql with the --log option:
or place the following in your
my.cnf
file:Either one will log all queries to log_file_name.
You can also log only slow queries using the
--log-slow-queries
option instead of--log
. By default, queries that take 10 seconds or longer are considered slow, you can change this by settinglong_query_time
to the number of seconds a query must take to execute before being logged.You should be aware that mysql logging on really impacts performance, but it can be a wise thing to do.
I usually leave it on on the dev server (except when it drives us insane :))
OS / mysql version:
Adding logging (example, I don't think
/var/log/...
is the best path on Mac OS but that worked:Restarted Mysql
Result: