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.
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.
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;
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
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
$
评论