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 update operation without where condition in MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article shows you how to prevent update operations without where conditions in MySQL. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Add-U login to the database

Click (here) to collapse or open

[root@master] # mysql-uroot-pmysql-U

Mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 12

Server version: 5.7.19-log Source distribution

Copyright (c) 2000, 2017, 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 >

Mysql > use test

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changed

Mysql > show tables

+-+

| | Tables_in_test |

+-+

| | T1 |

+-+

1 row in set (0.00 sec)

Mysql > show create table T1

+- - - -- +

| | Table | Create Table |

+- - - -- +

| | T1 | CREATE TABLE `t1` (

`admin_ id`int (11) NOT NULL DEFAULT'0'

`admin_ name` varchar (200) NOT NULL

`password` varchar (200) NOT NULL

`role`int (11) NOT NULL DEFAULT'1'

`last_login_ time`datetime DEFAULT NULL

`last_login_ ip`varchar (16) DEFAULT''

`admin_ status` int (11) NOT NULL DEFAULT'1'

`create_ time`datetime DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

+- - - -- +

1 row in set (0.00 sec)

Mysql > update T1 set admin_status=1234

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

You can see here that the database gives a hint that update operations without where conditions are not allowed.

2. According to this characteristic, change the system environment variable.

Vi / etc/profile

Alias mysql='mysql-U'

Source / etc/profile

3. Log in to MySQL with normal command to test

Click (here) to collapse or open

[root@master] # mysql-uroot-pmysql

Mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 14

Server version: 5.7.19-log Source distribution

Copyright (c) 2000, 2017, 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 > use test

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changed

Mysql > update T1 set admin_status=1234

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

The above is how to prevent update operations without where conditions in MySQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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