aqac0w
Last Updated: February 25, 2016
·
4.619K
· tralamazza
781bbe3e6880c14f783d044f2ff05e50

MySQL would you please DROP USER IF EXISTS!?

MySQL can drop almost anything conditionally (e.g. databases, tables, procedures ...), but a user.

So if you have a DB bootstrap script that removes pesky default anonymous users, you probably want to do something like:

DROP USER ''@'localhost';

Now run it again on the same DB and you probably know what happens.

To my delight I found this little workaround gem by Steve Bearman from a April 2006 MySQL thread still working like a charm (tested on MySql 5.5). So now instead you do:

GRANT USAGE ON *.* TO ''@'localhost';
DROP USER ''@'localhost';

And voilá.

Say Thanks
Respond

1 Response
Add your response

26681
2e1e340e378a26f2c69c6dd418060374

Thanks! It actually works with any user. Very handy for automatic provisioning!

over 1 year ago ·