- Lab
- A Cloud Guru
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.
Path 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
stosh
using 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
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';
-
Challenge
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';
-
Challenge
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');
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.