I've just discovered that I can create a user and grant right to it on a given database even if that DB doesn't exist yet (it will be created in a second step).
MariaDB [(none)]> CREATE USER foo2@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.08 sec)
MariaDB [(none)]> GRANT SELECT, UPDATE, DELETE ON DBNotCreatedYet.* TO 'foo2'@'localhost';
Query OK, 0 rows affected (0.01 sec)
Do you think this procedure can cause troubles and it'd be better to create the DB and THEN granting rights to a user on it? I'd prefer not to put a constraint about what operation to do first but I don't want to run into troubles.
Best Answer
I think I have the answer: it works.
I leave it here just in case someone else run into the same doubt.
Here is an example:
The user can work in the specified DB, with the granted rights, even if it was created (and granted its rights) before the DB was created.