mysql - create user if not exists?
Unfortunately there isn't such a thing, so if you try to create a user that already exists you'll get an error. But there is a nice workaround.
GRANT ALL PRIVILEGES ON `database`.* TO 'user'@'localhost';
...will do exactly that. If the user exists, the privileges will be granted, if the user doesn't exist, it will be created first.
Watch out for sql-mode in your mysql configuration. In order for this to work, the setting must not contain NO_AUTO_CREATE_USER
.
Example:
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
Written by Markus Hausammann
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#