Skip to Content
MySQL Cookbook, 2nd Edition
book

MySQL Cookbook, 2nd Edition

by Paul DuBois
November 2006
Intermediate to advanced
977 pages
30h 42m
English
O'Reilly Media, Inc.
Content preview from MySQL Cookbook, 2nd Edition

Logging Interactive mysql Sessions

Problem

You want to keep a record of what you did in a mysql session.

Solution

Create a tee file.

Discussion

If you maintain a log of an interactive MySQL session, you can refer back to it later to see what you did and how. Under Unix, you can use the script program to save a log of a terminal session. This works for arbitrary commands, so it works for interactive mysql sessions, too. However, script also adds a carriage return to every line of the transcript, and it includes any backspacing and corrections you make as you’re typing. A method of logging an interactive mysql session that doesn’t add extra messy junk to the logfile (and that works under both Unix and Windows) is to start mysql with a --tee option that specifies the name of the file in which to record the session:[5]

%mysql --tee=tmp.out cookbook

To control session logging from within mysql, use \T and \t to turn tee output on or off, respectively. This is useful if you want to record only certain parts of a session:

mysql>\T tmp.out
Logging to file 'tmp.out'
mysql> \t
Outfile disabled.

A tee file contains the statements that you enter as well as the output from those statements, so it’s a convenient way to keep a complete record of them. It’s useful, for example, when you want to print or mail a session or parts of it, or for capturing statement output to include as an example in a document. It’s also a good way to try statements to make sure that you have the syntax correct before putting ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Cookbook, 3rd Edition

MySQL Cookbook, 3rd Edition

Paul DuBois
MySQL 8 Cookbook

MySQL 8 Cookbook

Karthik Appigatla
MySQL Cookbook

MySQL Cookbook

Paul DuBois
MySQL Cookbook, 4th Edition

MySQL Cookbook, 4th Edition

Sveta Smirnova, Alkin Tezuysal

Publisher Resources

ISBN: 059652708XSupplemental ContentErrata Page