高頻事故:UPDATE/DELETE 忘加 WHERE 導致全表覆蓋/清空。MySQL 內建 --safe-updates (短參 -U) 模式可從客戶端層面強制阻擋無條件寫操作。
# 以 -U 登入 mysql -uroot -poldboy123 -S /data/3306/mysql.sock -U mysql> DELETE FROM oldboy.student; ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column mysql> DELETE FROM oldboy.student WHERE Sno=5; Query OK, 1 row affected (0.02 sec)
# 當前會話 alias mysql='mysql -U' # 永久生效 (所有用戶) echo "alias mysql='mysql -U'" >> /etc/profile . /etc/profile
mysql 客戶端工具,不影響應用程式連接池、JDBC、ORM 等WHERE 條件包含索引列 (KEY column),單純 WHERE 1=1 仍會被擋LIMIT 子句也可滿足條件 (如 DELETE FROM t LIMIT 100)