–safe-updatesオプションを指定してDBに接続すると、プライマリーキーを
指定しないとUPDATEやDELETEなどの更新クエリーを実行出来ないように
するオプションです。WHERE句を忘れてデータすべて変更してしまったなど
と焦らないようにする為に良いかもしれません。
[root@colinux mysql5130]# mysql -u root -p --prompt="\u@\h-DB:\d>" --safe-updates Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.30 MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. root@localhost-DB:(none)>use test Database changed root@localhost-DB:test>show tables; +----------------+ | Tables_in_test | +----------------+ | T1 | +----------------+ 1 row in set (0.00 sec) root@localhost-DB:test>select * from T1; +----+------------+-------------+ | id | name | comment | +----+------------+-------------+ | 1 | SHOW WARIN | 1111111 | | 2 | SHOW WARIN | 22222222222 | +----+------------+-------------+ 2 rows in set (0.00 sec) root@localhost-DB:test> root@localhost-DB:test>update T1 set comment="test update"; ERROR 1175 (HY000): You are using safe update mode and you tried to update a tab le without a WHERE that uses a KEY column root@localhost-DB:test>update T1 set comment="test update" where id = 1; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 root@localhost-DB:test>select * from T1; +----+------------+-------------+ | id | name | comment | +----+------------+-------------+ | 1 | SHOW WARIN | test update | | 2 | SHOW WARIN | 22222222222 | +----+------------+-------------+ 2 rows in set (0.00 sec) root@localhost-DB:test>
※primaryキーを指定しないと更新出来ないので、ある程度まとまったデータ
を更新する場合は、BEGIN TRAN ~ COMMIT TRAN/ROLLBACK TRAN
などで処理を戻せるようにする事で対応する事も可能ですね。