MySQL Create a log file with last queries

User Avatar
👤 admin
🔴 Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
📅 Created: 11 Feb 2021 at 12:04
👀 Viewed: 37 times
✉️ Send Email

What is MySQL?

MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses. MySQL was owned and sponsored by the Swedish company MySQL AB, which was bought by Sun Microsystems In 2010, when Oracle acquired Sun, Widenius forked the open-source MySQL project to create MariaDB.

How to show the last queries in MySQL?

You can enable a general query log for diagnostic purposes. Generally you don't log all SELECT queries on a production server though it, it's a performance killer.
Edit your MySQL config, e.g. /etc/mysql/my.cnf - look for, or add, a line like this:


[mysqld]

log = /var/log/mysql/mysql.log

Restart mysql to pick up that change, now you can:


tail -f /var/log/mysql/mysql.log


Hey presto, you can watch the queries as they come in.

We want to remind you that this type of log is only for testing and not for production environments. Please after finishing with your testing disable this log.

We hope you enjoyed this article. if that is so please rate this page with the stars bellow and subscribe to our YouTube channel.

If you want to comment: Login or Register