Add the following to your .bashrc
or .profile
file in your user's home path:
# Log all queries.
function mysqlLog {
drush sql-cli << EOF
SET GLOBAL query_cache_type=OFF;
SET global log_output = 'FILE';
SET global general_log_file='/tmp/query.log';
SET global general_log = 1;
EOF
echo "Queries will be saved at /tmp/query.log"
}
# Stop logging all queries.
function mysqlUnlog {
sudo service mysql restart
}
$ mysqlLog
Queries will be saved at /tmp/query.log
Then, open a local website or run a command that executes MySQL queries. When you are done run the following to stop logging:
$ mysqlUnlog
[sudo] password for juampy:
mysql stop/waiting
mysql start/running, process 24464
Logged queries can be found at /tmp/query.log
.