mysql错误:ERROR 1175: You are using safe update mode 解决方法_MySQL
程序员文章站
2022-05-24 20:42:04
...
操作mysql数据库,删除表中的某一行数据提示如下错误:ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
错误提示:正在使用安全更新模式,尝试更新表没有使用键列的where条件;
原因是:mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1,所以才会出现更新失败的情况。
举例如下:
mysql> select * from test; +----+--------+ | id | name | +----+--------+ | 1 | anglea | | 2 | baby | | 3 | jerry | | 4 | tom | | 5 | yong | +----+--------+ mysql> delete from test where name='yong'; 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> show variables like 'sql_safe%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | sql_safe_updates | ON | +------------------+-------+
下面是SQL_SAFE_UPDATES变量为0和1时的取值说明:
SQL_SAFE_UPDATES有两个取值0和1, 或ON 和OFF;
SQL_SAFE_UPDATES = 1,ON时,不带where和limit条件的update和delete操作语句是无法执行的,即使是有where和limit条件但不带key column的update和delete也不能执行。
SQL_SAFE_UPDATES =0,OFF时,update和delete操作将会顺利执行。那么很显然,此变量的默认值是1。
所以,出现1175错误的时候,可以先设置SQL_SAFE_UPDATES的值为0 OFF,然后再执行更新;
以下2条命令都可以;
mysql> set sql_safe_updates=0; mysql> set sql_safe_updates=off; mysql> show variables like 'sql_safe%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | sql_safe_updates | OFF | +------------------+-------+ mysql> delete from test where name='yong'; Query OK, 1 row affected (0.00 sec)
更改只在当前生效,退出mysql,再次登录后恢复为默认。
推荐阅读
-
Mysql Error Code: 1175. You are using safe update mode and y_MySQL
-
MySQL错误:ERROR 1175: You are using safe update mode 解决方法
-
MySQL错误:ERROR 1175: You are using safe update mode 解决方法
-
Mysql Error Code: 1175. You are using safe update mode and y_MySQL
-
mysql错误:ERROR 1175: You are using safe update mode 解决方法_MySQL
-
mysql错误:ERROR 1175: You are using safe update mode 解决方法_MySQL
-
ERROR CODE: 1175 YOU ARE USING SAFE UPDATE MODE AN
-
ERROR CODE: 1175 YOU ARE USING SAFE UPDATE MODE AN