Tracing MySql Transactions

Anyone who has had to troubleshoot or support systems built on a SQL Server database knows and loves the Profiler Tool, which allows you to see all of the queries submitted to a database.

Web page database interaction tends to be simpler, and until recently, I never had to troubleshoot a situation that was so complex that I needed to trace its database interactions. This week, though, I was looking at a function to save some records. I had a print_r at the top to prove to myself that the records were there, and I saw other records in the list in the database after the run, but my last ones were missing.

It had to be that the records were being deleted behind the insert. I needed a trace to figure out what was coming behind me to delete perfectly good records.

It turns out to be pretty easy. First, I edited the configuration file for mysql, which I found in /etc/mysql/my.cnf. (All of my work was on an Ubuntu server running both Apache and MySql. Needless to say, there are other environments where paths and file names are different.)

I found this section of the config file:

I changed the general_log value from 0 to 1, and restarted mysql.

I then ran my page, and opened the log file named in the configuration: /var/log/mysql/mysql.log.

Posted in Linix/Apache, mysql, php, Web Apps | Tagged , , , , , , , , | Leave a comment

Comments are closed.