登陆MySQL时加上-U选项
mysql -uroot -pxxxx -U
帮助解释
[root@localhost ~]# mysql --help|grep '\-U'
-U, --safe-updates Only allow UPDATE and DELETE that uses keys.
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
大概意思是:update 和delete操作时候必须带上where条件,且是索引列。
下面测试结果
"root@localhost:mysql.sock [pxs]>update t1 set id3='hehe';
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
"root@localhost:mysql.sock [pxs]>update t1 set id3='hehe' where id = 22;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
"root@localhost:mysql.sock [pxs]>delete from t1;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
"root@localhost:mysql.sock [pxs]>delete from t1 where id=22;
Query OK, 1 row affected (0.02 sec)