转载:mysql sql_safe_updates 分析

今天看到一个很实用的功能,mysql_safe_updates.
只是对功能做了转载,具体原理可以看一下

delete from table t  where true ;  
update t set col='new_value'  where true 

由于漏掉where条件或者拼接SQL后的where条件部分为true,这时整个表都被删除/更新了...

但是sql_safe_update开启后,mysql server层在调用mysql_update/mysql_delete时对where和limit进行判断后决定是否执行

因此在使用mysql的应用中,避免此类低级错误的方法:

1、应用仔细检查(小心才能使得万年船啊~)

2、敏感操作开启sql_safe_updates

posted @ 2019-09-12 17:47  luyuqiang  阅读(76)  评论(0编辑  收藏  举报