CREATE USER IF NOT EXISTS ...
A new user is created without a problem. An existing user returns that error, but the docs read that CREATE USER
for MySQL > 5.7.6 supports it.
MySQL Version is
Ver 14.14 Distrib 5.7.11, for osx10.9 (x86_64) using EditLine wrapper
Sample
<root:none> CREATE USER IF NOT EXISTS 'foo'@'localhost' IDENTIFIED BY 'bar';
--------------
CREATE USER IF NOT EXISTS 'foo'@'localhost' IDENTIFIED BY 'bar'
--------------
Query OK, 0 rows affected (0.00 sec)
<root:none> CREATE USER IF NOT EXISTS 'foo'@'localhost' IDENTIFIED BY 'bar';
--------------
CREATE USER IF NOT EXISTS 'foo'@'localhost' IDENTIFIED BY 'bar'
--------------
ERROR 1396 (HY000): Operation CREATE USER failed for 'foo'@'localhost'
Suggestions?
create user
failed as user is already exists – Nagendra Nigade Feb 14 '16 at 14:15IF NOT EXISTS
is supposed to handle this error just as it does everywhere else. Is this a known bug or am I not using it correctly? – Vishal Feb 14 '16 at 14:21select * from user where user='name';
or you can take count from this query. OR As you are creating user you have to give grants to user. In mysql you can use grant command to create user if not already created likeGRANT ALL PRIVILEGES ON db_name.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Grant will create user if not already exists. – Nagendra Nigade Feb 14 '16 at 14:33IF NOT EXISTS
doesn't work as documented. – Vishal Feb 14 '16 at 15:15