Mysql-u Prevent human error operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.