Mysql 5.6 Query Logging

Every once in awhile I do something that I think should be easy.  It should be easy to turn on mysql query logging but it took me a little too long to find examples. So to save everyone time here is what I did.

 

I’m on a Mac so please adjust accordingly.

$ cd /etc
$ sudo vi my.cnf

[mysqld]
general_log=1
slow_query_log=1
# Define where the log file should be
general_log_file=/tmp/mysql_general.log
slow_query_log_file=/tmp/mysql_slow_queries.log
# Set this to the number of seconds a query must take to be considered "slow"
long_query_time = 1
# Also, if you want to log all queries that don't use indexes:
# log-queries-not-using-indexes

Now the log file is at /tmp/ so I’m going to tail it while I do some of my programming.

$ cd /tmp
$ sudo tail -f mysql_general.log

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.