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.

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

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

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

Baron Schwartz

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

James Cohen

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

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

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

Sweet!

Learn something new every day!