Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to prevent human misoperation of MySQL database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to prevent human misoperation of MySQL database". In daily operation, I believe that many people have doubts about how to prevent human misoperation of MySQL database. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to prevent human misoperation of MySQL database". Next, please follow the editor to study!

MySQL help description

[root@binghe~] # mysql-- help | grep dummy-U,-- i-am-a-dummy Synonym for option-- safe-updates,-U. I-am-a-dummy FALSE

When you add the option-U to the mysql command, when you issue UPDATE or DELETE without the WHERE or LIMIT keyword, the MySQL program refuses to execute.

Specify-U login test

[root@binghe~] # mysql-uroot-proot-S / data/3306/mysql.sock-U Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 14 Server version: 5.7.24-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be 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 you tried to update a table without a WHERE that uses a KEY column mysql > quit Bye

Tip: it cannot be deleted without conditions, and the goal can be achieved.

Specify alias

We can alias the command to operate MySQL to prevent others and DBA from mismanipulating the database, and it is very easy to alias the command to operate MySQL. Here, we go straight to the example, as shown below.

[root@binghe~] # alias mysql='mysql-U' [root@binghe~] # mysql-uroot-poldboy123-S / data/3306/mysql.sock Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 15 Server version: 5.7.24-log MySQL Community Server (GPL) 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 you tried to update a table without a WHERE that uses a KEY column mysql > delete from oldboy.student where Sno=5; Query OK, 1 row affected (0.02 sec) mysql > quit Bye

After setting alias mysql='mysql-U'in the command line session, it is only valid for the current session, and after the command line that currently connects to the server is closed, the session expires, and the alias setting becomes invalid. If you want to close the session terminal that connects to the server, the alias setting is still in effect, or multiple sessions can use this alias to manipulate the database, we can add the command to set the alias to the / etc/profile system environment variable, as shown below.

[root@binghe~] # echo "alias mysql='mysql-U'> > / etc/profile [root@binghe~] #. / etc/profile [root@binghe~] # tail-1 / etc/profile alias mysql='mysql-U'

In this way, when we exit the session terminal that currently connects to the server, the alias setting of MySQL is still valid. Every time we connect to the server, we do not have to reset the command alias of MySQL in the current session.

At this point, the study on "how to prevent human misoperation of MySQL database" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report