MySQL error code: 1175 during UPDATE in MySQL Work

2018-12-31 23:29发布

I'm trying to update the column visited to give it the value 1. I use MySQL workbench, and I'm writing the statement in the SQL editor from inside the workbench. I'm writing the following command:

UPDATE tablename SET columnname=1;

It gives me the following error:

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 ....

I followed the instructions, and I unchecked the safe update option from the Edit menu then Preferences then SQL Editor. The same error still appear & I'm not able to update this value. Please, tell me what is wrong?

16条回答
荒废的爱情
2楼-- · 2018-12-31 23:39

All that's needed is: Start a new query and run:

SET SQL_SAFE_UPDATES = 0;

Then: Run the query that you were trying to run that wasn't previously working.

查看更多
还给你的自由
3楼-- · 2018-12-31 23:40

Follow the following steps before executing the UPDATE command: In MySQL Workbench

  1. Go to Edit --> Preferences
  2. Click "SQL Editor" tab and uncheck "Safe Updates" check box
  3. Query --> Reconnect to Server // logout and then login
  4. Now execute your SQL query

p.s., No need to restart the MySQL daemon!

查看更多
伤终究还是伤i
4楼-- · 2018-12-31 23:42

I found the answer. The problem was that I have to precede the table name with the schema name. i.e, the command should be:

UPDATE schemaname.tablename SET columnname=1;

Thanks all.

查看更多
姐姐魅力值爆表
5楼-- · 2018-12-31 23:42

Since the question was answered and had nothing to do with safe updates, this might be the wrong place; I'll post just to add information.

I tried to be a good citizen and modified the query to use a temp table of ids that would get updated:

create temporary table ids ( id int )
    select id from prime_table where condition = true;
update prime_table set field1 = '' where id in (select id from ids);

Failure. Modified the update to:

update prime_table set field 1 = '' where id <> 0 and id in (select id from ids);

That worked. Well golly -- if I am always adding where key <> 0 to get around the safe update check, or even set SQL_SAFE_UPDATE=0, then I've lost the 'check' on my query. I might as well just turn off the option permanently. I suppose it makes deleting and updating a two step process instead of one.. but if you type fast enough and stop thinking about the key being special but rather as just a nuisance..

查看更多
美炸的是我
6楼-- · 2018-12-31 23:45
SET SQL_SAFE_UPDATES=0;

OR

Go to Edit --> Preferences

Click SQL Queries tab and uncheck Safe Updates check box

Query --> Reconnect to Server

Now execute your sql query

查看更多
低头抚发
7楼-- · 2018-12-31 23:46

It looks like your MySql session has the safe-updates option set. This means that you can't update or delete records without specifying a key (ex. primary key) in the where clause.

Try:

SET SQL_SAFE_UPDATES = 0;

Or you can modify your query to follow the rule (use primary key in where clause).

查看更多
登录 后发表回答