更新查询在 mysql 工作台中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33971357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update query not working in mysql workbench
提问by Hyman Ferzi
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 的表要禁用安全模式,请切换首选项 -> SQL 编辑器中的选项并重新连接。
回答by Manoj Salvi
In mysql workbench the safe mode is enabled by default, so if your WHEREclause doesn't have a key it will prevent running the query. Try disabling that using these steps -
在 mysql workbench 中,默认情况下启用安全模式,因此如果您的WHERE子句没有键,它将阻止运行查询。尝试使用这些步骤禁用它 -
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),然后再次运行您的查询。
回答by Sarath Chandra
MySQLhelps you particularly avoid updating/deleting multiple rows in one shot. To achieve that, it doesn't allow you to run UPDATEqueries without passing the ID parameter. This is called as the SAFE UPDATESmode.
MySQL帮助您特别避免一次性更新/删除多行。为此,它不允许您在UPDATE不传递 ID 参数的情况下运行查询。这称为SAFE UPDATES模式。
As said by @ManojSalvi, you can set it permanently from the settings.
正如@ManojSalvi 所说,您可以从设置中永久设置它。
In case you wanna temporarily disable the said SAFE UPDATEmode, 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;
回答by Blag
[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...
对我来说很好...
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
结果:
| firstname | lastname | password |
|-----------|----------------|----------|
| Pramod | Alfred Schmidt | 123 |
| test | hello h. | *** |
回答by Ashish Chowdhary
"Safe mode" is on by default in MySQL workbench. You can change it go to mysqlworkbench at the top left –> preferences–> sql editor –> uncheck the safe mode and then try reconnecting. Or you can just type
“安全模式”在 MySQL 工作台中默认处于开启状态。您可以在左上角的 mysqlworkbench 中更改它 –> 首选项 –> sql 编辑器 –> 取消选中安全模式,然后尝试重新连接。或者你可以只输入
SET SQL_SAFE_UPDATES = 0;
SET SQL_SAFE_UPDATES = 0;
This will do the same.
这将做同样的事情。

