国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

mysql的歷史命令記錄,~/.mysql_history

2019-01-09 14:02:06 4913

~/.mysql_history文件中記錄每個用戶使用數(shù)據(jù)庫的操作命令


root用戶的mysql操作,~/.mysql_history


transfor用戶的mysql操作,/home/transfor/.mysql_history


[root@cp-mysql01-new ~]# tail -20 /root/.mysql_history 

show variables like '%resolve%';

show variables like '%connection%';

 show global status like ‘Max_used_connections;

 show global status like ‘Max_used_connections';

show global status like 'max_user_connections';

show global status like 'max_used_connections';

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;


不過這個文件會把所有操作記錄下來,包括創(chuàng)建用戶和修改用戶的明文密碼。萬一被人攻擊,獲取該文件內(nèi)容,非常危險。


這個文件是mysql編譯安裝時默認(rèn)配置好的,不容易修改。但是最好不要保存,僅僅刪除是不行的,要直接將其軟連接到垃圾箱:


rm ~/.mysql_history


ln -s /dev/null ~/.mysql_history


如果確實想將一些操作記錄下來,可以在/etc/my.cnf配置文件的[client]組臨時添加:

[client]

tee=/tmp/mysql.history


tee命令添加完成后,無需重啟mysql服務(wù),所以僅對當(dāng)前打開的客戶端記錄mysql操作命令


等操作使用完成后,注釋



~/.mysql_history文件產(chǎn)生原理


因為mysql本身就是一個shell,每次mysql連接退出后,都會把此次操作信息記錄到~/.mysql_history文件中


如果該文件不存在,會先創(chuàng)建再記錄(像rm,或者剛安裝的mysql)


此文件的名字和路徑,是根據(jù)MYSQL_HISTFILE這個環(huán)境變量來設(shè)置的,默認(rèn)是~/.mysql_history,修改文件名和路徑:

vim ~/.bash_profile

export MYSQL_HISTFILE=/home/jason/.my_history


./etc/profile重新初始化后,生效


提交成功!非常感謝您的反饋,我們會繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進一步的反饋信息:

在文檔使用中是否遇到以下問題: