MySQL – Grant user permission to create table as long is it has a prefix in the name

MySQLpermissions

I'd like to grant a user permission to create tables in a database so long as the table has a particular prefix, let's say example_.

I've tried the following:


$ mysql -u root -p
mysql> CREATE DATABASE example;
mysql> CREATE USER xyz@localhost IDENTIFIED BY 'password';
mysql> GRANT CREATE ON example.`example_*` to xyz@localhost;

However, when I log in to example as xyz I'm unable to create tables:


$ mysql -p -u xyz example
mysql> CREATE TABLE example_table (id INT);
ERROR 1142 (42000): CREATE command denied to user 'xyz'@'localhost' for table 'example_table'

Is this even possible? If so, how?

Best Answer

There is not a wildcard facility of that sort.

Don't prefix columns with the table name. If you need qualification, do tablename.columnname.

Don't prefix tables with the table name. If you need qualification, do dbname.tablename.

If necessary, move all the examples into a separate db and GRANT suitable permissions to suitable users for that database.