How to view executed SQL

Re: How to view executed SQL

by Ken Task -
Number of replies: 0
Picture of Particularly helpful Moodlers

Davo's way is perhaps best for true programmers.   There is another thang one could do:

one could setup mysql to log, have mysql log queries, then tell mysql to turn off logging.   What ever is done when logging is on is seen in logs.

Don't leave it on or those could easily fill up a lot of space on DB server.

Settings in my.cnf

# for logging
general_log_file=/var/log/mysql/mysql-general.log
slow_query_log_file=/var/log/mysql/mysql-slow.log

One would have to create the log files (which contain nothing at first):

touch /var/log/mysql/mysql-slow.log
and
touch /var/log/mysql/mysql-general.log

Then set their ownerships/permissions for the mysqld user

chown mysql:mysql /var/log/mysql/mysql-slow.log
chown mysql:mysql /var/log/mysql/mysql-general.log

so that mysql can write to them

# to turn on one or both:
mysql -e 'set global log = 1' -u root -p'[password]'
mysql -e 'set global log_slow_queries = 1' -u root -p'password'
mysql -e 'set global slow_query_log = 1' -u root -p'password'

If you install multitail one could watch those logs in realtime.

multitail -i /var/log/mysql/mysql-general.log -i /var/log/mysql/mysql-slow.log -i /var/log/httpd/access_log -i /var/log/httpd/error_log;

# to turn off
# set global slow_query_log = 0
# set global log_slow_queries = 0
# set global log = 0;

Once off, those logs can be copied out of /var/log/mysql/ saved as a text file
(they are ascii anyway), download them and inspect with notepad/textedit or
any text editor

'spirit of sharing', Ken


Average of ratings: Useful (2)