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!
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.
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';
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.
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.
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)
you can try this
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'some_pass';
grant all privileges on B.* to 'myuser'@'localhost' identified by 'some_pass';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With