Home  >  Article  >  Database  >  MySQL错误:ERROR 1175: You are using safe update mode 解决方法

MySQL错误:ERROR 1175: You are using safe update mode 解决方法

WBOY
WBOYOriginal
2016-06-07 14:59:171457browse

操作MySQL数据库,删除表中的某一行数据提示如下错误:ERROR 1175 (HY000): You are using safe update mode and you tried to u

MySQL错误:ERROR 1175: You are using safe update mode 解决方法

[日期:2015-09-14] 来源:Linux社区  作者:mofansheng [字体:]

操作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,所以才会出现更新失败的情况。 

举例如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

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

查看设置:

1

2

3

4

5

6

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;    

1

2

3

4

5

6

7

8

9

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,再次登录后恢复为默认。

本文永久更新链接地址

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn