Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new user in mysql with access to only certain databases

Tags:

mysql

Dont know if this is possible.

I need to create a new mysql user with access to only databases with database name with prefix say user_db_.

I have a php application in which when a new user is added it creates a database user_db_'userid'. Suppose three users are created such that their databases are user_db_1, user_db_2, user_db_3.

I need to create a new user say user_accounts which has access to only user_db_1, user_db_2, user_db_3,..........,user_db_n.

like image 477
Avinash Avatar asked Oct 11 '25 21:10

Avinash


1 Answers

Use the following code for granting privileges on a particular DB.

grant all privileges on DB_NAME.* to 'USER'@'REMOTE_IP' identified by 'PASSWORD';
like image 180
K S Nidhin Avatar answered Oct 14 '25 14:10

K S Nidhin