Logging all queries executed on MySQL database

Submitted by Jochus on Mon, 12/11/2012 - 23:23 | Posted in: Database


I wanted to debug some SQL queries which are coming from my data access layer (JPA with Hibernate) and which are being send to my MySQL server. The following steps are needed:

  • Create the file /etc/my.cnf (I installed MySQL manually from a .pkg installer, so the file is not there by default - you have to create it manually)
  • Add the following lines:

    [mysqld]
    log=/tmp/mysql-query.log
  • Create the .log file:
    $ sudo touch /tmp/mysql-query.log
  • Allow MySQL daemon to write in file:
    $ sudo chown _mysql /tmp/mysql-query.log
  • Restart MySQL daemon:
    ~ $ cd /usr/local/mysql/support-files/
    /usr/local/mysql/support-files $ sudo ./mysql.server restart

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.