root@127.0.0.1 : test 07:58:34> set sql_safe_updates=0;
Query OK, 0 rows affected (0.00 sec)
root@127.0.0.1 : test 07:58:43> show variables like ‘sql_safe_updates‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| sql_safe_updates | OFF |
+------------------+-------+
1 row in set (0.00 sec)
root@127.0.0.1 : test 07:58:55> select * from t;
+-------+
| pd |
+-------+
| hello |
| mysql |
+-------+
2 rows in set (0.00 sec)
root@127.0.0.1 : test 07:58:59> begin;
Query OK, 0 rows affected (0.00 sec)
root@127.0.0.1 : test 07:59:04> update t set pd=‘MySQL‘;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
root@127.0.0.1 : test 07:59:12> select * from t;
+-------+
| pd |
+-------+
| MySQL |
| MySQL |
+-------+
2 rows in set (0.00 sec)
# sql_safe_updates=1,即开启
root@127.0.0.1 : test 08:00:00> set sql_safe_updates=1;
Query OK, 0 rows affected (0.00 sec)
root@127.0.0.1 : test 08:00:11> show variables like ‘sql_safe_updates‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| sql_safe_updates | ON |
+------------------+-------+
1 row in set (0.00 sec)
root@127.0.0.1 : test 08:00:16> select * from t;
+-------+
| pd |
+-------+
| hello |
| mysql |
+-------+
2 rows in set (0.00 sec)
root@127.0.0.1 : test 08:00:25> begin;
Query OK, 0 rows affected (0.00 sec)
root@127.0.0.1 : test 08:00:27> update t set pd=‘MySQL‘;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column