The ability to create users and manage privileges provides a granular level of security and access in MySQL. In this lab, you will be tasked with creating new users in the MySQL server and deleting users that no longer need access. Once the users are created, you will need to grant the appropriate privileges to each user so that they have access to the correct databases and tables within the server.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create the Following Four Users on the MySQL Server: `corey`, `will`, `mike`, and `myles`, and Allow Logins from `localhost` Only, Using the Password `Linux4you!`
Once logged in to the MySQL server, run the following command to create the users:
mysql> CREATE USER 'corey'@'localhost' IDENTIFIED BY 'Linux4you!','will'@'localhost' IDENTIFIED BY 'Linux4you!','mike'@'localhost' IDENTIFIED BY 'Linux4you!','myles'@'localhost' IDENTIFIED BY 'Linux4you!';
- Delete the User `stosh` from the MySQL Server
Delete the user
stosh
using the DROP statement:mysql>DROP USER 'stosh'@'localhost';
- Grant Privileges on the Newly Created Users According to the Information Provided in the Instructions
Grant all privileges on the
dev
database to thecorey
user:mysql> GRANT ALL ON dev.* TO 'corey'@'localhost';
Grant INSERT and SELECT privileges on the
products
table in thedev
database towill
:mysql> GRANT SELECT, INSERT ON dev.products TO 'will'@'localhost';
Grant ALL privileges on the
prod
database to themike
user:mysql> GRANT ALL ON prod.* TO 'mike'@'localhost';
Grant SELECT privileges on the
products
table in theprod
database tomyles
user:mysql> GRANT SELECT ON prod.products TO 'myles'@'localhost';
- Revoke the INSERT Privilege from the `kenny` User on the `orders` Table in the `prod` Database
Revoke the INSERT privilege from the
kenny
user running the following command:mysql> REVOKE INSERT ON prod.orders FROM 'kenny'@'localhost';
- Optionally, Validate the Updated Privileges by Testing User Access
Ensure that the user
corey
does not have access to theprod
database. Run the following as thecorey
user:mysql> SELECT * FROM prod.orders;
Ensure that the user
will
does not have access to theorders
table on thedev
database. Run the following as thewill
user:mysql> SELECT * FROM dev.orders;
Ensure that the user
mike
does not have access to thedev
database. Run the following as themike
user:mysql> SELECT * FROM dev.orders;
Ensure that the user
myles
does not have access to theorders
table in theprod
database. Run the following as themyles
user:mysql> SELECT * FROM prod.orders;
Ensure that the user
kenny
does not have INSERT privileges on theorders
table in theprod
database. Run the following as thekenny
user:mysql> INSERT INTO prod.orders (orderID,userName,orderType,purchaseDate) VALUES (4,'mike','laptop','2018-04-08');