1.报错
执行:
-- 修改数据
update
student -- 学生表
set
chinese=92.8,math=95.6
where
id=1;
| 0 | 25 | 10:00:04 | update student -- 学生表 set chinese = 92.8,math = 95.6 where id = 1 | 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 Editor and reconnect. | 0.078 sec |
2.分析
这是因为MySql运行在safe-updates模式下,该模式会导致非主键条件下无法执行update或者delete命令。
可以通过以下SQL进行状态查询:
-- 查询状态
show variables like 'SQL_SAFE_UPDATES';
| sql_safe_updates | OFF |
3.解决方法
执行下面的sql,关闭safe-updates模式:
-- 解决方法(关闭safe-update模式)
SET SQL_SAFE_UPDATES = 0; -- 或SET SQL_SAFE_UPDATES = false;
| 3 | 32 | 10:22:24 | SET SQL_SAFE_UPDATES = 0 | 0 row(s) affected | 0.000 sec |
这篇博客介绍了在MySQL中遇到的安全更新模式(safe-updates)导致的更新或删除操作受限的问题。当尝试在非主键条件下更新表时,会出现错误提示。解决方法是通过执行`SET SQL_SAFE_UPDATES=0;`来关闭safe-updates模式。博客内容包括错误信息、问题原因和解决方案的详细步骤。

被折叠的 条评论
为什么被折叠?



