Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Create user with rights only for specific db [duplicate]

Tags:

mysql

I would need to create MySQL user programatically with the privileges only for specific db. Say there are databases a,b,c and I would need to create user who has rights only for B. I am sure its possible but my googling was not successful. Thank you!

like image 348
Petr Avatar asked Nov 02 '09 07:11

Petr


People also ask

How do I grant specific privileges to a user in MySQL?

The GRANT statement allows you to set MySQL access permissions, using the following syntax: mysql> GRANT privilege ON privilege_level TO account_name; Type the following to grant `SELECT` and `INSERT` privileges to a local user on the `strongdm` database: mysql> GRANT SELECT, INSERT ON strongdm.

How do I give access to a specific database in MySQL?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name. * TO 'username'@'localhost';

Which accounts have specific privileges MySQL?

ALL PRIVILEGES – Grants all privileges to a user account. CREATE – The user account is allowed to create databases and tables. DROP - The user account is allowed to drop databases and tables. DELETE - The user account is allowed to delete rows from a specific table.

How are permissions implemented in my sequel?

In MySQL, the user permissions are granted to the MySQL user account which determines operations that can be performed in the server. These user permissions may differ in the levels of privileges in which they are applied for several query executions.


2 Answers

grant all
    on B.*
to
    'user'@localhost
identified by
    'password'

The user 'user' with password 'password' now have access to all tables in the database 'B'. (Of course you need to run this query with a high priv user)

like image 91
Björn Avatar answered Sep 27 '22 17:09

Björn


you can try this

 CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'some_pass';
 grant all privileges on B.* to 'myuser'@'localhost' identified by 'some_pass';
like image 27
RRUZ Avatar answered Sep 27 '22 17:09

RRUZ