tags:

views:

420

answers:

2

I run several queries from mysql command line on my linux box (Fedora Os). I would like to capture all these automatically to a file. I know there is command in Linux called history and then you can pipe it to a file. Is there anything similar for MYSQL. I would like to save all my scripts and sql query just for reference sake at a later point in time.

Help Appreciated.

+1  A: 

MySQL stores your query history in the file ~/.mysql_history. Certain characters are escaped in this file. Space becomes \040; backslash becomes \\. You can replace these escape sequences using sed or your favorite text editor.

Ayman Hourieh
for some reason, I cannot see this file.
CodeToGlory
If it's like most other history files written by processes like bash, pgsql, and so forth, it doesn't get written unless you exit cleanly from the mysql command line. If you just close your terminal window or kill the mysql process, nothing will get saved.
Barry Brown
Also, what is the output of 'echo $MYSQL_HISTFILE'? Is it set to /dev/null by any chance?
Ayman Hourieh
A: 

Alternatively, turn on the mysql query log.

in your /etc/mysql/my.cnf file (or wherever your OS puts it), put a section in the config like:

[mysqld]
log=/var/log/mysql/mysqld.log

Then, every query will be logged to this file.

Chaos