目录安全模式设置测试1.无where的update和delete2、非索引键的delete3.索引键的delete总结大家肯定听说过,有些开发者由于个人失误,在d
大家肯定听说过,有些开发者由于个人失误,在delete或者update语句的时候没有添加where语句,导致整个表数据错乱。
mysql安全模式:mysql发现delete、update语句没有添加where或者limit条件时会报错。整个sql将无法执行,有效防止了误删表的情况。
在Mysql中通过如下命令查看状态:
show variables like 'sql_safe_updates';
默认是OFF状态,将状态设置为ON即可:
set sql_safe_updates=1;
//打开set sql_safe_updates=0;
//关闭设置为ON之后
打开安全模式进行测试
delete from t_user
delete from t_user
> 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
> 时间: 0.001s
update t_user set name='123'
update t_user set name='123'
> 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
> 时间: 0.001s
delete from t_user where name='123'
delete from t_user where name='123'
> 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
> 时间: 0.007s
如果delete的where条件不是索引键,则必须要添加limit才可以。
delete from t_user where name='123' limit 1
delete from t_user where name='123' limit 1
> Affected rows: 0
> 时间: 0.002s
delete from t_user where group_id='123'
delete from t_user where group_id='123'
> Affected rows: 0
> 时间: 0s
如果设置了sql_safe_updates=1
,那么update
语句必须满足如下条件之一才能执行成功
delete
语句必须满足如下条件之一才能执行成功
到此这篇关于mysql如何能有效防止删库跑路的文章就介绍到这了,更多相关mysql 防止删库内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: mysql如何能有效防止删库跑路
本文链接: https://www.lsjlt.com/news/137177.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-13
2024-05-13
2024-05-13
2024-05-13
2024-05-12
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0