如何保护mysql表免遭意外批量更新

时间:2021-05-20 17:04:12

Occasional updates statements without "where" clause may easily destroy all your data, I'm always getting nervous when typing UPDATE statement in mysql console, being afraid to press enter before typing "where".

So, I'm wondering if it is possible to protect table from update queries w/o "where" clause on mySQL level? Kind of simply disable it.
And yes, I'm well aware of backups :-) Thanks!

没有“where”子句的偶尔更新语句可能很容易破坏你的所有数据,我在mysql控制台中输入UPDATE语句时总是感到紧张,在输入“where”之前不敢按回车键。所以,我想知道是否有可能在mySQL级别上保护表不受更新查询w / o“where”子句的影响?简单地禁用它。是的,我很清楚备份:-)谢谢!

2 个解决方案

#1


2  

Not an insult: turn on --i-am-a-dummy mode.

不是侮辱:打开 - 我是一个虚拟模式。

#2


0  

MySQL has the the --safe-updates switch, most other databases don't. This is why in cases like that I personally always start writing with the where clause:

MySQL有--safe-updates开关,大多数其他数据库没有。这就是为什么在我这样的情况下我总是开始用where子句写作:

where x > 134;

and then move the cursor to the beginning and add:

然后将光标移动到开头并添加:

update whatever set a = 2 where x > 134;

this way the query has a syntax error until the very moment it is valid.

这样查询就会出现语法错误,直到它有效。

#1


2  

Not an insult: turn on --i-am-a-dummy mode.

不是侮辱:打开 - 我是一个虚拟模式。

#2


0  

MySQL has the the --safe-updates switch, most other databases don't. This is why in cases like that I personally always start writing with the where clause:

MySQL有--safe-updates开关,大多数其他数据库没有。这就是为什么在我这样的情况下我总是开始用where子句写作:

where x > 134;

and then move the cursor to the beginning and add:

然后将光标移动到开头并添加:

update whatever set a = 2 where x > 134;

this way the query has a syntax error until the very moment it is valid.

这样查询就会出现语法错误,直到它有效。