4

MySQL does not allow you to specify an if not exists clause in a create user statement (despite the fact that create table and create procedure do support this). There was a feature request for this in 2005 but the MySQL devs have done sod all about it, so it's probably not going to happen anytime soon:

http://bugs.mysql.com/bug.php?id=15287

I'm trying to emulate this functionality with the following statement:

if (select ifnull((select 1
                     from mysql.user
                    where User = 'recuser'
                      and Host = '%'), 0) = 0) then
  create user 'recuser'@'%' identified by password 'blah';
end if;

but MySQL complains about the syntax in the if statement - I can't see anything wrong with it, hopefully someone else can point out what the issue is.

Thanks!

2 Answers 2

10

Denis answered your precise question, but there are other ways around your problem: see my answer to mysql create user only when the user doesn't exist (where there is also an example of a similar stored procedure as well)

Sign up to request clarification or add additional context in comments.

Comments

-2

MySQL supports flow control constructs within stored procedures only.

2 Comments

... and it doesn't have system stored procedures to add/remove users, and you can't prepare a create user statement because it's not supported. Another reason to "love" MySQL I guess.
You told him something he essentially already knows, instead of helping fix his problem...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.