EmergencyEMERGENCY? Get 24/7 Help Now!

Logging your MySQL command line client sessions

 | July 8, 2008 |  Posted In: Insight for DBAs


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.

Peter Zaitsev

Peter managed the High Performance Group within MySQL until 2006, when he founded Percona. Peter has a Master's Degree in Computer Science and is an expert in database kernels, computer hardware, and application scaling.


  • 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?


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

  • Well “man script” does it on my Linux distribution if you do not have it installed you can check some online man pages to see if it will work for you


  • 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.

  • I almost always use screen when diagnosing server issues or running OS updates.

    I can have a mytop, top and other tools running and toggle between them easily. As mentioned, screen has a logging option tool.

    I wrote a screen tutorial some time ago:

  • 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