Granting and revoking access to users
You can restrict the user to access specific databases or tables and also only specific operations, such as SELECT
, INSERT
, and UPDATE
. For granting privileges to other users, you should have the GRANT
privilege.
How to do it...
During the initial setup, you can use the root user to grant privileges. You can also create an administrative account to manage the users.
Granting privileges
- Grant the
READ ONLY(SELECT)
privileges to thecompany_read_only
user:
mysql> GRANT SELECT ON company.* TO 'company_read_only'@'localhost'; Query OK, 0 rows affected (0.06 sec)
The asterisk (*
) represents all tables inside the database.
- Grant the
INSERT
privilege to the newcompany_insert_only
user:
mysql> GRANT INSERT ON company.* TO 'company_insert_only'@'localhost' IDENTIFIED BY 'xxxx';
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> SHOW WARNINGS\G *************************** 1. row *************************** Level: Warning Code: 1287 Message: Using GRANT...