I want to test if a user exists. If it does I should do nothing. If it doesn't I should create it and grant privileges.
The concept code that I came up with is this:
IF EXISTS(SELECT 1 FROM mysql.user WHERE user = 'web_service_user' AND host = '%') THEN
\! echo "EXISTS";
ELSE
\! echo "DOES NOT";
END IF;
Hower when I run this I get this output:
EXISTS
DOES NOT
ERROR 1064 (42000) at line 1 in file: 'test_conditional.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ELSE
END IF' at line 3
So how do I test (in a conditional) if a user exists?
I know of this: mysql create user if not exists
However I would need still need to check if the user "was just created" in order to know If I need to execute the grant statements.