题: 我如何能 禁用MySQL历史?我不’希望mysql记住我从mysql键入的先前命令>提示。这对我很重要,因为当我键入一些包含密码的sql命令时,我看到了〜/ .mysql_history中存储的明文密码,我没有’t want to happen.
回答: 重击历史记录功能 将在命令行中键入的Unix命令存储在〜/ .bash_history文件中。类似于bash shell,mysql存储在mysql中键入的命令> prompt in the 〜/ .mysql_history 文件。
在本文中,让我们回顾一下如何禁用mysql历史记录。
1.从mysql执行一些sql命令> prompt
从unix命令行连接到mysql并执行一些sql命令,如下所示。
$ mysql -u root -pyour-password mysql> show databases; mysql> use information_schema; mysql> show tables; mysql> select table_name, table_rows from tables;
注意: 现在,如果按向上箭头,您将看到所有先前的命令’在mysql提示符下输入ve。
2.〜/ .mysql_history文件存储mysql历史记录
从mysql命令提示符退出,并查看〜/ .mysql_history文件,该文件将包含您从mysql命令提示符下执行的所有sql命令。
$ cat 〜/ .mysql_history select * from versions; show databases; use information_schema; show tables; select table_name, table_rows from tables;
3.使用MYSQL_HISTFILE环境变量禁用mysql历史记录
首先,删除〜/ .mysql_history文件
$ rm 〜/ .mysql_history
接下来,设置 MYSQL_HISTFILE env变量到/ dev / null
$ export MYSQL_HISTFILE=/dev/null $ set | grep MYSQ MYSQL_HISTFILE=/dev/null
现在,登录到mysql并执行一些sql命令。您’将会注意到〜/ .mysql_history文件不再被创建。
$ 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.通过将.mysql_history指向/ dev / null来禁用mysql历史记录
首先,删除〜/ .mysql_history文件
$ rm 〜/ .mysql_history
接下来,创建〜/ .mysql_history的符号链接,指向/ dev / null,如下所示。
$ 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
现在,登录到mysql并执行一些sql命令。您’将会注意到〜/ .mysql_history文件为空,并且不存储任何以前键入的命令。
$ 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 $
如果您喜欢这篇文章,您可能还会喜欢..
![]() |
![]() |
![]() |
![]() |
或者,您可以在〜/目录中使用.bash_logout文件。在调用注销之前,将执行此文件中的命令。只是把echo -n>〜/ .mysq_history,当您退出系统时,将清除mysql_history。