MySQL -U防止人為誤操作

來源:互聯網
上載者:User

標籤: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防止人為誤操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.