Debug of SQL Statements

To debug a SQL Statement from an application you first need to create a general logfile

on linux command line do

  • touch /var/log/mysql-trace.log
  • chown mysql:mysql  /var/log/mysql-trace.log

if this is done start your sql session as SUPER ADMIN !!

mysql -u root -p

then tell mysql to use the trace log /var/log/mysql-trace.log

mysql> SET GLOBAL general_log_file = '/var/log/mysql-trace.log';
Query OK, 0 rows affected (0.00 sec)

and enable the logging with
mysql> SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)

 

Please keep in note that this logfile on some databases may grow very fast with megabytes per second. To disable logging do a
mysql> SET GLOBAL general_log = 'OFF';
Query OK, 0 rows affected (0.11 sec)

In /var/log/mysql-trace.log you will have an output like this:


 

/usr/libexec/mysqld, Version: 5.1.73-log (Source distribution). started with:
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
141015  6:50:09 4091518 Query   INSERT INTO ....

                        4091518 Query   SELECT ....

 

 

 

 

 

Back to Top
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.