We have already covered MySQL Command History in Linux. This article is about how to disable it. The command history file can contain potentially sensitive information. And, it is important to safeguard it from evolving threats.
One way out could be to actively manage the MySQL command history file: $HOME/.mysql_history
We can keep the file and regularly remove sensitive data from it. But, that is not the right approach for certain environments. So, the best way is to entirely disable it.
Disable MySQL command history in Linux
Technically, we can’t enable or disable the MySQL command history. There is no such option available. But, there is a workaround.
And, that comes through a Null Device: /dev/null. Whatever we write to the Null device gets discarded. We can’t read anything out of this file. Most often the data that is irrelevant to the context is written to Null Device.
So, what we do here is point the output of MySQL command history to a Null Device. As we already know, all the commands we enter are saved in the $HOME/.mysql_history file.
But, before that remove the MySQL command history file itself through the rm command. Open a terminal and issue the following:
rm $HOME/.mysql_history
It is better to create a symbolic link to /dev/null through the ln -s command.
ln -s /dev/null $HOME/.mysql_history
From now onwards, anything we enter in the MySQL prompt won’t get stored.
In conclusion, we have covered here how to disable MySQL command history in Linux.
Additional Info:
At some stage, if you wish to keep MySQL command history then first remove the linking file $HOME/.mysql_history
This can be done using the rm command utility:
rm $HOME/.mysql_history
Now, open the MySQL prompt and enter the command there. The moment you enter the first command or text it would create a command history file on its own.