- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Creating Users and Managing Privileges in MySQL
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.
Lab Info
Table of Contents
-
Challenge
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!'; -
Challenge
Delete the User `stosh` from the MySQL Server
Delete the user
stoshusing the DROP statement:mysql>DROP USER 'stosh'@'localhost'; -
Challenge
Grant Privileges on the Newly Created Users According to the Information Provided in the Instructions
Grant all privileges on the
devdatabase to thecoreyuser:mysql> GRANT ALL ON dev.* TO 'corey'@'localhost';Grant INSERT and SELECT privileges on the
productstable in thedevdatabase towill:mysql> GRANT SELECT, INSERT ON dev.products TO 'will'@'localhost';Grant ALL privileges on the
proddatabase to themikeuser:mysql> GRANT ALL ON prod.* TO 'mike'@'localhost';Grant SELECT privileges on the
productstable in theproddatabase tomylesuser:mysql> GRANT SELECT ON prod.products TO 'myles'@'localhost'; -
Challenge
Revoke the INSERT Privilege from the `kenny` User on the `orders` Table in the `prod` Database
Revoke the INSERT privilege from the
kennyuser running the following command:mysql> REVOKE INSERT ON prod.orders FROM 'kenny'@'localhost'; -
Challenge
Optionally, Validate the Updated Privileges by Testing User Access
Ensure that the user
coreydoes not have access to theproddatabase. Run the following as thecoreyuser:mysql> SELECT * FROM prod.orders;Ensure that the user
willdoes not have access to theorderstable on thedevdatabase. Run the following as thewilluser:mysql> SELECT * FROM dev.orders;Ensure that the user
mikedoes not have access to thedevdatabase. Run the following as themikeuser:mysql> SELECT * FROM dev.orders;Ensure that the user
mylesdoes not have access to theorderstable in theproddatabase. Run the following as themylesuser:mysql> SELECT * FROM prod.orders;Ensure that the user
kennydoes not have INSERT privileges on theorderstable in theproddatabase. Run the following as thekennyuser:mysql> INSERT INTO prod.orders (orderID,userName,orderType,purchaseDate) VALUES (4,'mike','laptop','2018-04-08');
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.