---
title: "MySQL的SQL_SAFE_UPDATES"
author: "aaronchenwei"
date: "2014-12-16T08:51:45Z"
tags: []
categories: ["数据库"]
slug: "mysql-sql-safe-updates"
draft: false
lastmod: "2014-12-16T08:51:45Z"
id: 2166589
url: "https://aaronchenwei.iteye.com/blog/2166589"
---

在MySQL Workbench中，如果执行类似以下的语句，


```sql

UPDATE tablename SET columnname=0;

```


可能会遇上如下的出错信息

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.

具体的原因，可以参见MySQL的文档<http://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html#option_mysql_safe-updates>

可以通过以下方法来解决

```sql

SET SQL_SAFE_UPDATES=0;

```


当然了，如果想查询当时变量的值，也可以通过如下方法

```sql

SHOW VARIABLES LIKE 'sql_safe_updates';

```

或是

```sql

select @@sql_safe_updates;

```