Question: How do I disable mysql history? I don’t want mysql to remember the previous commands that I typed from the mysql> prompt. This is important for me, as when I type some sql commands that contains passwords, I see the clear text password stored in the ~/.mysql_history, which I don’t want to happen.
Answer: Bash history feature stores the Unix commands typed in the command line in the ~/.bash_history file. Similar to bash shell, mysql stores the commands typed in the mysql> prompt in the ~/.mysql_history file.
In this article, let us review how to disable mysql history.
1. Execute some sql commands from mysql> prompt
Connect to mysql from the unix command line and execute few sql commands as shown below.
$ mysql -u root -pyour-password mysql> show databases; mysql> use information_schema; mysql> show tables; mysql> select table_name, table_rows from tables;
Note: Now, if you press up arrow, you can see all the previous commands you’ve typed from the mysql prompt.
2. ~/.mysql_history file stores the mysql history
Exit from the mysql command prompt and view the ~/.mysql_history file that will contain all the sql commands you executed from the mysql command prompt.
$ cat ~/.mysql_history select * from versions; show databases; use information_schema; show tables; select table_name, table_rows from tables;
3. Disable mysql history using MYSQL_HISTFILE environment variable
First, remove the ~/.mysql_history file
$ rm ~/.mysql_history
Next, set the MYSQL_HISTFILE env variable to /dev/null
$ export MYSQL_HISTFILE=/dev/null $ set | grep MYSQ MYSQL_HISTFILE=/dev/null
Now, login to the mysql and execute few sql commands. You’ll notice that ~/.mysql_history file is not getting created anymore.
$ mysql -u root -pyour-password mysql> show databases; mysql> use information_schema; mysql> show tables; mysql> select table_name, table_rows from tables; $ cat ~/.mysql_history cat: /home/ramesh/.mysql_history: No such file or directory
4. Disable mysql history by pointing .mysql_history to /dev/null
First, remove the ~/.mysql_history file
$ rm ~/.mysql_history
Next, create a symbolic link of ~/.mysql_history pointing to /dev/null as shown below.
$ ln -s /dev/null ~/.mysql_history $ ls -l .mysql_history lrwxrwxrwx 1 ramesh admin 9 Dec 26 19:18 /home/ramesh/.mysql_history -> /dev/null
Now, login to the mysql and execute few sql commands. You’ll notice that ~/.mysql_history file is empty and does not store any previously typed commands.
$ mysql -u root -pyour-password mysql> show databases; mysql> use information_schema; mysql> show tables; mysql> select table_name, table_rows from tables; $ cat ~/.mysql_history $
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 3 comments… read them below or add one }
Or you can use .bash_logout file in your ~/ directory. Commands in this files are executed before logout is called. Just put echo -n > ~/.mysq_history, and when u will logout of the system, mysql_history will be cleared.
doing the bash_logout is not enough, because every admin with a brain uses screen and these kind of sessions can be very long – so it is important to not create the mysql_history in the first place, not only delete-after-creation. RokP, you would not have passed the exam.
There is no need to run `mysql -u root -pyour-password`, as it will get your password in the .bash_history file. Instead use `mysql -u root -p` without any password, so mysql will prompt for it.