MySQL Forums
Forum List  »  Newbie

Create User (if not exists)
Posted by: Shawn Berg
Date: June 02, 2014 03:49PM

I have a SQL script that creates a MySQL database, needed tables, inserts some basic info, creates the application's MySQL user, and assigns privileges to that MySQL user on the application's database.

Now, if an installation goes awry and I need to reinstall their database, tables, etc. back to factory default, I import the same SQL script. With databases and tables, I can simply use the "IF NOT EXISTS" directive and with my INSERT statements I can simply use "IGNORE" to pass over values that are still there.

The issue I am running into is if the db specific user is still present in the MySQL users table, the script stops processing and errors out,

#1396 - Operation CREATE USER failed for 'MyDBUser'@'%'

SO I guess my question is this: is there a way or directive similar to IF NOT EXISTS or IGNORE that I can use with CREATE USER that will check to see if a user exists before trying to create the user? In other words...to ignore recreating the user if the MySQL user already exists?

Options: ReplyQuote


Subject
Written By
Posted
Create User (if not exists)
June 02, 2014 03:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.