Is it safe to disable temporarily SQL_SAFE_UPDATES to perform a mySQL query?

2.2k views Asked by At

Sometimes I end up to need to perform update like the following:

SET SQL_SAFE_UPDATES = 0;
//My update query [..]
SET SQL_SAFE_UPDATES = 1;

While I perform those three above statements... SQL_SAFE_UPDATES configuration is disabled. Since I believe that this setup has a clear meaning. What could be the drawback on disabling temporary this feature?

Is there a chance to enclose all the statements in a atomic transaction ? To prevent others to execute unsafe queries in the meanwhile?

1

There are 1 answers

1
Mike On

Safe updates are better summed up with the alternative command-line argument "--i-am-a-dummy". Other than removing some power from your query, they don't make it any "safer". They insist on limits to queries, conditions on removes etc which are single-shot checks. To use Marc B's analogy, it's not whether you will crash the car but whether the car will explode when you turn the key. If it doesn't the first time then it's not going to the next. It's more akin to asking "is it okay to run a command with sudo under Linux" - perhaps not in a general way but sometimes you can't achieve anything unless you do.

In this case, all you're saying when you turn it off is "I know what I'm doing so just get on with it and stop moaning." If you're happy with the query and that it does what you want it to then there's no need to set the safe updates at all.

I never even knew it existed. You build up the query, check that it looks right, backup the table, run the query, check the results and call it good. After your second or third system, your SQL errors aren't going to be simple enough to be caught by this anyway.