Tuesday, March 15, 2011

What is the mysql command to pipe all command line input to a file on Fedora OS?

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.

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

    CodeToGlory : for some reason, I cannot see this file.
    Barry Brown : 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.
    Ayman Hourieh : Also, what is the output of 'echo $MYSQL_HISTFILE'? Is it set to /dev/null by any chance?
  • 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.

0 comments:

Post a Comment