How to log all MySQL queries to a file

This tutorial describes how you can enable MySQL to log every query to a file. All of this is possible without the need to restart MySQL.

Create query log file

touch /var/log/mysql_queries.txt

Set file permissions so that MySQL server can write to the file

chown mysql:mysql /var/log/mysql_queries.txt

Enable query logging

Login to the MySQL server and the run the following queries:

SET global log_output = 'FILE';
SET global general_log_file='/var/log/mysql_queries.txt';
SET global general_log = 1;

Disable query logging

Login to the MySQL server and the run the following query:

SET global general_log = 0;