Where the open source database community meets: Use code PERCONA75 and secure your spot for Percona Live.  Register

Logging your MySQL command line client sessions

July 8, 2008
Author
Peter Zaitsev
Share this 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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tom Krouper
Tom Krouper
17 years ago

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

Tom Krouper
Tom Krouper
17 years ago

I was thinking it was another MySQL tool. Perfect, thanks.

Baron Schwartz
17 years ago

Another way to do this is to use screen. CTRL-A H will log the screen to a file.

James Cohen
James Cohen
17 years ago

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.

jeffatrackaid
17 years ago

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:
http://www.rackaid.com/resources/linux-tutorials/general-tutorials/linux-screen.cfm

jeffatrackaid
17 years 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.

James Parks
James Parks
13 years ago

Sweet!

Learn something new every day!

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved