简体   繁体   English

更新查询在 mysql 工作台中不起作用

[英]Update query not working in mysql workbench

I have a MySql query, which is given below:我有一个 MySql 查询,如下所示:

UPDATE signup SET lastname='Lastname', password='123'
WHERE firstname='Firstname';

I am using MySql Workbench to execute the query.我正在使用 MySql Workbench 来执行查询。

But it's not updating the row and shows this 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 in Preferences -> SQL Editor and reconnect.您正在使用安全更新模式并且您尝试更新没有使用 KEY 列的 WHERE 的表 要禁用安全模式,请切换 Preferences -> SQL Editor 中的选项并重新连接。

In mysql workbench the safe mode is enabled by default, so if your WHERE clause doesn't have a key it will prevent running the query.在 mysql 工作台中,默认情况下启用安全模式,因此如果您的WHERE子句没有键,它将阻止运行查询。 Try disabling that using these steps -尝试使用这些步骤禁用它 -

Edit > Preferences > Sql Editor > uncheck the "Safe Updates" Edit > Preferences > Sql Editor > uncheck the "Safe Updates"

Note - try reconnecting the server ( Query > Reconnect to Server ) and than run your query again.注意- 尝试重新连接服务器( Query > Reconnect to Server ),然后再次运行您的查询。

MySQL helps you particularly avoid updating/deleting multiple rows in one shot. MySQL可以帮助您避免一次性更新/删除多行。 To achieve that, it doesn't allow you to run UPDATE queries without passing the ID parameter.为此,它不允许您在不传递 ID 参数的情况下运行UPDATE查询。 This is called as the SAFE UPDATES mode.这称为SAFE UPDATES模式。

As said by @ManojSalvi, you can set it permanently from the settings.正如@ManojSalvi 所说,您可以从设置中永久设置它。

In case you want to temporarily disable the SAFE UPDATE mode, you can try the following:-如果您想暂时禁用SAFE UPDATE模式,您可以尝试以下操作:-

SET SQL_SAFE_UPDATES = 0;
UPDATE signup SET lastname='Lastname', password='123'
WHERE firstname='Firstname';
SET SQL_SAFE_UPDATES = 1;

[edit] @ManojSalvi got it, workbench related [编辑] @ManojSalvi 明白了,工作台相关

MySQL error code: 1175 during UPDATE in MySQL Workbench MySQL 错误代码:1175 在 MySQL Workbench 中的 UPDATE 期间


Work fine for me...对我来说很好...

SQL Fiddle SQL小提琴

MySQL 5.6 Schema Setup : MySQL 5.6 架构设置

CREATE TABLE t
    (`firstname` varchar(6), `lastname` varchar(14), `password` varchar(3))
;

INSERT INTO t
    (`firstname`, `lastname`, `password`)
VALUES
    ('Pramod', 'Alfred', '***'),
    ('test', 'hello h.', '***')
;
UPDATE t SET lastname='Alfred Schmidt', password='123' WHERE firstname='Pramod';

Query 1 :查询 1

select * from t

Results :结果

| firstname |       lastname | password |
|-----------|----------------|----------|
|    Pramod | Alfred Schmidt |      123 |
|      test |       hello h. |      *** |

"Safe mode" is on by default in MySQL workbench. “安全模式”在 MySQL 工作台中默认处于开启状态。 You can change it go to mysqlworkbench at the top left –> preferences–> sql editor –> uncheck the safe mode and then try reconnecting.您可以在左上角的 mysqlworkbench 中更改它 –> 首选项 –> sql 编辑器 –> 取消选中安全模式,然后尝试重新连接。 Or you can just type或者你可以只输入

SET SQL_SAFE_UPDATES = 0; SET SQL_SAFE_UPDATES = 0;

This will do the same.这将做同样的事情。

I don't think it has anything to to with the SAFE UPDATES since you have clearly stated WHERE you wanted to make changes.我认为这与SAFE UPDATES没有任何关系,因为您已明确说明您想在WHERE进行更改。 I had the same issue, but I tried wrapping the column's name in backticks ` and it worked.我遇到了同样的问题,但我尝试将列的名称包含在反引号中 ` 并且它起作用了。 You can find backticks to the left of number 1 on the keyboard.您可以在键盘上的数字 1 左侧找到反引号。

One other thing you can try is to SELECT the table and double click on the item you want to UPDATE then apply the changes at the bottom right of the window.您可以尝试的另一件事是SELECT并双击要UPDATE的项目,然后应用窗口右下角的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM