登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

li.angshan 的博客

关注数据计算领域

 
 
 

日志

 
 
 
 

disable mysql history  

2011-01-07 15:25:39|  分类: mysql 管理 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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
$
  评论这张
 
阅读(444)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018