標籤:mysq alias table current reserve 就會 connect 無法 說明
在很多時候操作資料庫的時候,可能領導或DBA登陸了資料庫,在執行update和delete時,忘記了加where,可能會導致清空表的悲劇,所以-U的好處就體現了。
1、mysql -U的協助說明
-U, --safe-updates Only allow UPDATE and DELETE that uses keys.-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
在mysql命令加上選項-U後,當發出沒有WHERE或LIMIT關鍵字的UPDATE或DELETE時,mysql程式就會拒絕執行
2、指定-U登陸測試
[[email protected] ~]# mysql -uroot -p123 -S /data/3306/mysql.sock -UWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 14Server version: 5.5.32-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> delete from erlianzhang.test;ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY columnmysql> quitBye
不加條件就無法刪除,這樣就保護了資料,防止誤操作。
3、防止領導或DBA誤操作
[[email protected] ~]# alias mysql=‘mysql -U‘[[email protected] ~]# mysql -uroot -p123 -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 15Server version: 5.5.32-log MySQL Community Server (GPL)Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> delete from erlianzhang.test;ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY columnmysql> delete from erlianzhang.test where Sno=5;Query OK, 1 row affected (0.02 sec)mysql> quitBye[[email protected] ~]# echo "alias mysql=‘mysql -U‘" >>/etc/profile[[email protected] ~]# . /etc/profile[[email protected] ~]# tail -1 /etc/profilealias mysql=‘mysql -U‘
結論:在mysql 命令後加上-U參數後,當發出沒有WHERE或LIMIT關鍵字的UPDATE或DELETE時,mysql程式拒絕執行,防止誤操作給自己找麻煩。
轉載至:http://blog.51cto.com/oldboy/1321061
MySQL -U防止人為誤操作