In this article, we cover MySQL command history in Linux. Just like Bash, all the commands we enter in MySQL prompt are saved in a history file. At times, it is quite useful. On the other hand, we may want to get rid of it altogether due to security reasons.
If there is potentially sensitive information saved in MySQL command history file then anyone can access it. And, it creates a security issue.
This has happened to most of us, we enter a command and it generates an issue later. Like we created a column with the incorrect data type. If we have the command history enabled/active then we can always look up the statements from where things went wrong.
MySQL command history in Linux
MySQL writes all the commands we enter in a history file which can be found in the directory:
We can view the history file through the cat command-line utility:
Use more for one screen space at a time:
cat $HOME/.mysql_history | more
Apart from that, we can access command history through the Up/Down arrow keys through the MySQL prompt. It is similar to what we do to access Bash command history.
Furthermore, to clear MySQL command history all we need to do is delete the contents of the $HOME/.mysql_history history file. Use a text editor like Nano or Vim to do this.
In conclusion, we have covered MySQL command history in Linux. It is important to keep track of MySQL command history files as they may contain sensitive information. So, remove the sensitive data as and when necessary. This way we can keep the file. But, there is an option to disable the MySQL command history file in its entirety which we cover in the next article.