Logging your MySQL command line client sessions

PREVIOUS POST
NEXT POST

Baron recently wrote about very helpful but often forgotten about “Pager” feature of command line client. There is another one which falls into the same list – the –tee option.

Specifying –tee=/path/to/file.log you can get all session content (everything typed in and printed out) stored in the log file. Quite handy for example to keep track of changes done on production.

Moreover you can put tee=/logs/mysql.log in “mysql” section in my.cnf to have logging enabled automatically when you start the client.

If you’re looking to log session beyond MySQL command line client you can check out “script” tool.

PREVIOUS POST
NEXT POST

Comments

  1. Tom Krouper says

    I’ve heard of (and overlooked) the tee mysql client option. I’ve never heard of the “script” tool. Could you please let me know where I would find the “script” tool?

    Thanks,
    Tom

    PS: I think I know a lot about MySQL, then I find another thing I’d never heard of. :-)

  2. James Cohen says

    You can also access this from the MySQL client prompt:

    mysql> tee /tmp/session_log_file.txt
    Logging to file ‘/tmp/session_log_file.txt
    mysql> notee
    Outfile disabled.

  3. says

    No problem. I think screen is an oft-overlooked tool. Not related to logging, but for one client we have an admin box with mytop installed. They have 5 database servers in a master/slave farm setup. I have aliases setup to launch mytop and have it connect to each system. (e.g. mytopdb1 connects mytop to db1). I do this from inside screen and then can quickly toggle through mytop output on all boxes.

    There are probably cleaner ways to do this but I’ve found it handy to quickly check how queries are spreading over the slave pool as the load balancing is controlled on the application side.

Leave a Reply

Your email address will not be published. Required fields are marked *