Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 1019 Bytes

connect-to-a-database-in-safe-update-mode.md

File metadata and controls

31 lines (23 loc) · 1019 Bytes

Connect To A Database In Safe Update Mode

The MySQL client has a Safe-Updates Mode that you can use when connecting to a database. When this mode is active, the client will interrupt update and delete commands that don't specify a where clause that filters by a key value. That, or you need to explicitly limit the number of rows impacted by the query.

To start a connection in this mode, you can use either the --safe-updates flag or the cheekier --i-am-a-dummy flag.

$ mysql --i-am-a-dummy -h ::1 -P 3309 -u root -D my-database

Then if you try to do an unrestricted update or delete, you'll see the following message:

mysql> update users set email = '[email protected]';
ERROR 1175 (HY000): You are using safe update mode and you tried to update
a table without a WHERE that uses a KEY column.

This can also be set within the connection like so:

mysql> set sql_safe_updates=1;

source