Creating Users and Managing Privileges in MySQL

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

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 the corey user:

mysql> GRANT ALL ON dev.* TO 'corey'@'localhost';

Grant INSERT and SELECT privileges on the products table in the dev database to will:

mysql> GRANT SELECT, INSERT ON dev.products TO 'will'@'localhost';

Grant ALL privileges on the prod database to the mike user:

mysql> GRANT ALL ON prod.* TO 'mike'@'localhost';

Grant SELECT privileges on the products table in the prod database to myles 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 the prod database. Run the following as the corey user:

mysql> SELECT * FROM prod.orders;

Ensure that the user will does not have access to the orders table on the dev database. Run the following as the will user:

mysql> SELECT * FROM dev.orders;

Ensure that the user mike does not have access to the dev database. Run the following as the mike user:

mysql> SELECT * FROM dev.orders;

Ensure that the user myles does not have access to the orders table in the prod database. Run the following as the myles user:

mysql> SELECT * FROM prod.orders;

Ensure that the user kenny does not have INSERT privileges on the orders table in the prod database. Run the following as the kenny user:

mysql> INSERT INTO prod.orders (orderID,userName,orderType,purchaseDate) VALUES (4,'mike','laptop','2018-04-08');

Additional Resources

Our company has hired four new employees, and they need access to the MySQL server. As our company's database administrators, it's our job to create these user accounts and grant them specific privileges to databases and tables within the server. In addition to this, we will need to remove the user account of an employee who has recently left the company, and modify the privileges of a current employee who has been moved to a different position.

We'll use the following information to fulfill the objectives of this lab:

  • Create four new users: corey, will, mike, and myles. Each user should only be able to login in through localhost, using the password “Linux4you!”.
  • Delete the user stosh from the MySQL server.
  • Grant the appropriate privileges to the newly created users:
    • Grant all privileges on the dev database to the user corey.
    • Grant INSERT and SELECT privilages on the products table in the dev database to the user will.
    • Grant ALL privileges on the prod database to the user mike.
    • Grant SELECT privileges on the products table in the prod database to the user myles.
  • Revoke the INSERT privilege from the user kenny on the orders table in the prod database.

Additional Information:

  • Tasks in the MySQL database should be performed as the root user.
  • The root MySQL passwords is Linux4me!
  • All other users should use the Linux4you! password.
  • Do not update the password for the MySQL root. It is used for grading purposes.

What are Hands-on Labs

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!