MySQL 客戶端會將互動模式下執行的每條 SQL 寫入 ~/.mysql_history,若包含敏感資料(密碼、個資)需定期清理。
echo '' > ~/.mysql_history
# 或
cat /dev/null > ~/.mysql_history
在 ~/.bashrc 或 ~/.profile 加入:
export MYSQL_HISTFILE=/dev/null
重新登入後,MySQL 客戶端將不再寫入歷史檔。
history -chistory -wecho '' > ~/.bash_history/etc/profile 或 ~/.bashrc 的 HISTSIZE=1000 改為較小值或 0。HISTCONTROL=ignorespace): SELECT * FROM users WHERE pwd='secret';mysql -e "SQL" 非互動模式執行,不寫入歷史。~/.my.cnf 的 [client] 區塊,避免命令列明文。開啟 MySQL 一般查詢日誌或審計插件(MariaDB Audit Plugin、MySQL Enterprise Audit),集中記錄所有操作,而非依賴客戶端歷史檔。