How to log queries in real time using MariaDB/MySQL

Background

You have some sticky queries but you can’t see what’s happening. On certain website actions pages are just slow and you fully suspect the database queries are broken. Or you want to reverse engineer another piece of software’s database queries.

Solution

How you can turn on MySQL query logging. Go into the MySQL console and do:

SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/tmp/mysql.log';

Keep the console open, because when you’re done you want to set the “ON” above back to “OFF”.

Open another terminal and do:

tail -f /tmp/mysql.log

Reference

http://www.andrew-kirkpatrick.com/2015/04/quick-way-to-enable-mysql-general-query-log-without-restarting/

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top