MySQL Variables sql_safe_updates 数据库 参数变量解释及正确配置使用
本站中文解释
SQL_SAFE_UPDATES是MySQL的一个参数变量,用于防止客户端在更新操作期间误删除数据,从而保护数据库的安全。当开启SQL_SAFE_UPDATES参数时,MySQL会拒绝不带任何WHERE子句的更新和删除语句,以防止同时更新或删除大量行而导致不可挽回的数据丢失。
要设置SQL_SAFE_UPDATES参数,可以通过以下两种方法之一:
1. 在MySQL客户端中,执行以下命令:
SET SQL_SAFE_UPDATES=1
2. 修改MySQL服务器配置文件中的sql_safe_updates参数,将其值设置为1:
sql_safe_updates=1
官方英文解释
sql_safe_updates
| System Variable | sql_safe_updates |
|---|---|
| Scope | Global, Session |
| Dynamic | Yes |
| Type | Boolean |
| Default Value | OFF |
If this variable is enabled,
UPDATE and
DELETE statements that do not
use a key in the WHERE clause or a
LIMIT clause produce an error. This makes
it possible to catch UPDATE and
DELETE statements where keys
are not used properly and that would probably change or delete
a large number of rows. The default value is
OFF.
For the mysql client,
sql_safe_updates can be
enabled by using the
--safe-updates option. For more
information, see Using Safe-Updates Mode (–safe-updates).