Delete MySQL History in MySQL Command Line Interface

Do you notice that when you execute any query command in MySQL command line interface, the history can be trace by “Up” key. It might be a security expose when you created a new user via CLI, especially when you server is compromised or some other user sharing the same login trying to look through the historical command you have issued before.

We have a habit of creating user via command line interface, i.e issue the command below;

mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected] IDENTIFIED BY "thesecretpassword"

The command you have issued in the mysql CLI is usually store at user’s directory, i.e

$ ls /root/.mysql_history 
$ ls /home/user/.mysql_history 

Opps.. You found all the history command? It’s time to clean it up and stop mysql collecting the command you have issued before. There are 2 methods you can do with it;

1. Delete the command issued before

# cp /dev/null > /root/.mysql_history 
# cp /dev/null > /home/user/.mysql_history 

2. Stop collecting the history by redirecting the input into null.

# rm -rf /root/.mysql_history 
# ln -s /dev/null /root/.mysql_history 

By implementing the second method, it will permanently disable mysql collecting the command you have issued on command line interface.