How to view a processed (unprocessed) query from a prepared MySQLi statement?

I am creating a logging class for my PHP / MySQLi application. I can obviously write down the original prepared statement (with question marks), but without manually parsing it, is there anyway to see the actual raw query being executed in MySQL?

Thanks!

+4
source share
2 answers

Enable query logging in MySQL and control the mysql query log file.

In the my.cnf or my.ini file in the mysqld section add the directive:

 log = /path/to/my/log/file 
+1
source

There are many ways to view raw requests, sniff ports using tcpdump, mysql-proxy, or view mysqladmin -ppasswd, although you can do this for a short time:

 Start: echo "set global general_log_file=mysqllogfile;set global general_log=1;" | mysql -u root -ppasswd From now on all queries will appear in /var/lib/mysql/mysqllogfile Stop: echo "set global general_log=0;" | mysql -u root -ppasswd 

Do not forget to disconnect when done!

You can write queries to the mysql.general_log table:

 echo "set global log_output=TABLE;" | mysql -u root -ppasswd # restart logging echo "set global general_log=0;" | mysql -u root -ppasswd echo "set global general_log=1;" | mysql -u root -ppasswd 

Note that viewing the general_log table also forces them to be updated!

0
source

All Articles