In many cases when working with databases, it is possible for the leader or DBA to log in to the database, and when the update and delete are executed, forgetting where to add may result in a tragic emptying of the table, so the benefits of-u are reflected.
1, Mysql-u's help description
-U,--safe-updates only allow toUPDATE and DELETE that uses keys. for option--safe-updates,-U.
After the MySQL command plus option-u, the MySQL program rejects the update or delete without the Where or limit keyword
2. Specify-u login Test
[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 -Server Version:5.5. +-log MySQL Community Server (GPL) Copyright (c) -, -, Oracle and/or its affiliates. All rights reserved. Oracle isA registered trademark of Oracle Corporation and/or Itsaffiliates. Other names trademarks of their respectiveowners. Type'Help ;'Or'\h' forHelp. Type'\c'To clear the current input statement.mysql> Delete fromerlianzhang.test; ERROR1175(HY000): You areusingSafe Update mode and you tried to update a table without a WHERE that uses a KEY columnmysql>Quitbye
Without conditions can not be deleted, so that the protection of data, prevent misoperation.
3. Prevent the leader or DBA from mis-operation
[[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 theServer Version:5.5. +-log MySQL Community Server (GPL) Type'Help ;'Or'\h' forHelp. Type'\c'To clear the current input statement.mysql> Delete fromerlianzhang.test; ERROR1175(HY000): You areusingSafe Update mode and you tried to update a table without a WHERE that uses a KEY columnmysql> Delete fromErlianzhang.testwheresno=5; Query OK,1Row affected (0.02sec) MySQL>Quitbye[[email protected]~]# Echo"alias mysql= ' Mysql-u '">>/etc/Profile[[email protected]~]# . /etc/Profile[[email protected]~]# Tail-1/etc/Profilealias MySQL='Mysql-u'
Conclusion: After the MySQL command is added with the-u parameter, when an update or delete is issued that does not have a where or limit keyword, the MySQL program refuses to execute, preventing the error from getting in trouble.
Reprint to: http://blog.51cto.com/oldboy/1321061
Mysql-u Prevent human error operation