How to delete MySQL command line history

How to delete MySQL command line history

Introduction – On Unix or Linux system, the MySQL client writes a record of executed statements to a history file. By default, the history file is named .mysql_history and is created in your home directory. To specify a different file, set the value of the MYSQL_HISTFILE environment variable.

root@arunbagul:~# ls -l /root/.mysql_history
-rw——- 1 root root 71 2008-03-18 17:25 /root/.mysql_history

root@arunbagul:~# cat /root/.mysql_history
show databases;
select * from databases;
show status;
show variables;

If you do not want to maintain a history file, first remove .mysql_history if it exists, and then use either of the following techniques:

  • Set the MYSQL_HISTFILE variable to /dev/null. To cause this setting to take effect each time you log in, put the setting in one of your shell’s startup files.
  • Create .mysql_history as a symbolic link to /dev/null
  • ln -s /dev/null $HOME/.mysql_history

How to set Environment variable –

root@arunbagul:~# export MYSQL_HISTFILE=/dev/null


** Please add about command in .bashrc file in your home directory so that this variable will be set to /dev/null value every time you lonin ..

root@arunbagul:~# cat /root/.bashrc
Check the environment variable –

root@arunbagul:~# echo $MYSQL_HISTFILE

NOTE- It’s not secure to save all executed mysql command to $HOME/.mysql_history file!!


Arun Bagul

Similar Posts:

3 Replies to “How to delete MySQL command line history”

  1. ohh, thanks I was not aware of this mysql features… Many times I thought about mysql command line history and where mysql is storing it. but never took action to find it out…


Leave a Reply

Your email address will not be published.