How to log SQL queries (again)

Same task as Metformin er, different database. I have been doing some development over the last few days with Rails and MySQL. To cut a long story short I wanted to have a look at what queries were being sent to the database. This post describes one way of turning on logging for MySQL. I did all of this on Mac OS X so your mileage may vary.

  1. Create the log file
    
     >
    su  >
    cd /var/log  >
    touch mysqld.log  >
    chown mysql mysqld.log  
  2. Edit /etc/my.cnf
     
     [mysqld]  log = /var/log/mysqld.log  
     
  3. Restart the database

If you installed the MySQL Startup Item then you can restart the server simply by running:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart

Job done!

Leave a Reply