A case study of Mysql database preventing human-error operation _mysql

Source: Internet
Author: User

A lot of developers in the operation of the MySQL database has been a misuse of the situation, such as updating the database when the UPDATE statement forgot to add where conditions, it will cause extremely tragic results. This article in order to prevent the MySQL database error operation method to make the following detailed explanation:

1, MySQL help instructions

# mysql--help|grep dummy-  
 u,--i-am-a-dummy synonym for option--safe-updates,-U. 
I-am-a-dummy  FALSE

After the MySQL command plus option-u, when an update or delete without a where or limit keyword is issued, the MySQL program refuses to execute

2. Specify-u login Test

# mysql-uroot-poldboy123-s/data/3306/mysql.sock-u 
Welcome to the MySQL monitor. Commands End With; or \g. 
Your MySQL Connection ID 
is server version:5.5.32-log mysql Community Server (GPL) 
Copyright (c), 2013, O Racle and/or its affiliates. All rights reserved. 
Oracle is a registered trademark to Oracle Corporation and/or its 
affiliates. The other names may is trademarks of their respective 
owners. 
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement. 
Mysql> Delete from oldboy.student; 
ERROR 1175 (HY000): You are using Safe update mode and your tried to update a table without a WHERE that uses a KEY column< C11/>mysql> quit 
Bye

Hint: The condition cannot be deleted here, the purpose is achieved.

3, to make aliases to prevent DBA error operation

# alias Mysql= ' Mysql-u ' 
# mysql-uroot-poldboy123-s/data/3306/mysql.sock 
Welcome to the MySQL monitor. Commands End With; or \g. 
Your MySQL connection ID is 
server version:5.5.32-log mysql Community server (GPL) 
Type ' help; ' or ' \h ' to He Lp. Type ' \c ' to clear the current input statement. 
Mysql> Delete from oldboy.student; 
ERROR 1175 (HY000): You are using Safe update mode and your tried to update a table without a WHERE that uses a KEY column< C8/>mysql> Delete from oldboy.student where sno=5; 
Query OK, 1 row affected (0.02 sec) 
mysql> quit 
Bye 
# echo "Alias mysql= ' Mysql-u '" >>/etc/profile 
#/etc/profile 
# tail-1/etc/profile 
alias mysql= ' Mysql-u '

Conclusion: after the MySQL command plus option-u, when an update or delete without a where or limit keyword is issued, the MySQL program refuses to execute

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.