~/.mysql_history文件中記錄每一個用戶使用數據庫的操做命令mysql
root用戶的mysql操做,~/.mysql_historysql
transfor用戶的mysql操做,/home/transfor/.mysql_historyshell
[root@cp-mysql01-new ~]# tail -20 /root/.mysql_history 數據庫
show variables like '%resolve%';vim
show variables like '%connection%';bash
show global status like ‘Max_used_connections;spa
show global status like ‘Max_used_connections';io
show global status like 'max_user_connections';編譯
show global status like 'max_used_connections';table
show global variables like 'max_user_connections';
show global status like '%open%table%';
show variables like 'table%cache%';
show global status like 'thread%';
show variables like 'thread_cache_size';
show global status like 'qcache%';
show variables like 'query_cache%';
select count(id) from mop_bet_order_history;
use lottery;
select count(id) from mop_bet_order_history;
不過這個文件會把全部操做記錄下來,包括建立用戶和修改用戶的明文密碼。萬一被人攻擊,獲取該文件內容,很是危險。
這個文件是mysql編譯安裝時默認配置好的,不容易修改。可是最好不要保存,僅僅刪除是不行的,要直接將其軟鏈接到垃圾箱:
rm ~/.mysql_history
ln -s /dev/null ~/.mysql_history
若是確實想將一些操做記錄下來,能夠在/etc/my.cnf配置文件的[client]組臨時添加:
[client]
tee=/tmp/mysql.history
tee命令添加完成後,無需重啓mysql服務,因此僅對當前打開的客戶端記錄mysql操做命令
等操做使用完成後,註釋
~/.mysql_history文件產生原理
由於mysql自己就是一個shell,每次mysql鏈接退出後,都會把這次操做信息記錄到~/.mysql_history文件中
若是該文件不存在,會先建立再記錄(像rm,或者剛安裝的mysql)
此文件的名字和路徑,是根據MYSQL_HISTFILE這個環境變量來設置的,默認是~/.mysql_history,修改文件名和路徑:
vim ~/.bash_profile
export MYSQL_HISTFILE=/home/jason/.my_history
./etc/profile從新初始化後,生效