Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let MySQL users create databases, but allow access to only their own databases

Tags:

mysql

I want to have multiple a MySQL users to be able to issue commands like

CREATE DATABASE dbTest; 

But I also want each of these users to be able to see and access only their own databases.

All I could find was how to either create the databases by a DBA and grant the privileges on this database to the specific user:

GRANT ALL PRIVILEGES ON dbTest.* TO 'user'; 

or grant privileges on all databases to a user:

GRANT ALL PRIVILEGES ON *.* TO 'user'; 

But neither is what I want, because it needs to scale and be secure.

like image 608
eikes Avatar asked Jun 01 '10 13:06

eikes


People also ask

How do I allow users to create a database in MySQL?

mysql> CREATE USER 'linuxconfig'@'localhost' IDENTIFIED BY 'password_here'; Now it is time to grant permissions to our linuxconfig user so that it can create new databases. We will do this by granting them the CREATE permission with the following command. mysql> GRANT CREATE ON *.


1 Answers

You can use

GRANT ALL PRIVILEGES ON `testuser\_%` .  * TO 'testuser'@'%'; 

to grant the user testuser privileges on all databases with names beginning with testuser_.

This allows the testuser to create databases limited to names starting with testuser_

like image 127
rael_kid Avatar answered Sep 30 '22 18:09

rael_kid