sof sof - 1 year ago 71
MySQL Question

How to log queries to stdout on MySQL?

MySQL 5.6.26

Trying to log queries to stdout doesn't work below,

$ mysqld --general_log=1 --general_log_file=/dev/stdout

Answer Source

You can't, not directly. The query logs only go to files, tables or nowhere. They don't seem to go to /dev/stdout nor honor the - convention. Don't worry, there's a much better way.

If all you want to do is see the query log as it happens, you can stream the log file using various Unix utilities. tail -f is one option.

tail -f /path/to/query.log

I prefer opening the log with less and using the F command to keep reading as the file is added to. It's like tail -f but you can also scroll around and search the file.

$ less /path/to/query.log
/opt/local/lib/mysql56/bin/mysqld, Version: 5.6.27-log (Source distribution). started with:
Tcp port: 0  Unix socket: (null)
Time                 Id Command    Argument
151004 16:10:51     1 Connect   schwern@localhost as  on 
                    1 Query     select @@version_comment limit 1
151004 16:10:53     1 Query     select 1
151004 16:10:54     1 Quit      
Waiting for data... (interrupt to abort)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download