ak0r8a
Last Updated: February 25, 2016
·
719
· trinitronx
833761cd202c03e01ac63c55021a4eec

Protect yourself from trashing the production database

Here's a useful flag I found in the mysql manpage: mysql --i-am-a-dummy

· --safe-updates, --i-am-a-dummy, -U

Permit only those UPDATE and DELETE statements that specify which rows to modify by using key values. If you have set this option in an option file, you can override it by using --safe-updates on the command line. See the section called “MYSQL TIPS”, for more information about this option.

This should prevent you from making a mistake like this:
mysql> UPDATE tusers SET Fname = 'Oops', Lname = 'this-would-update-all-rows-in-tusers';
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

\(◠‿◠)/

Say Thanks
Respond

3 Responses
Add your response

3848
Squareprofile

Great tip, never heard of it before. =)

over 1 year ago ·
3854
D42a7264714dee5006b9c99d2567a320

Great find, thanks!

over 1 year ago ·
3919
546cb399441344941ff1052fae9563b4

You can even turn this on for all connections by setting the sql_safe_updates variable to 1. ( source )

over 1 year ago ·