Creating Secure MySQL User Accounts

MySQLMySQLBeginner
Practice Now

Introduction

In this project, you will learn how to create a new user in a MySQL database. This is a fundamental skill for database management and administration, as creating and managing user accounts is a crucial aspect of securing and controlling access to your database.

👀 Preview

Unfinished

🎯 Tasks

In this project, you will learn:

  • How to access the MySQL database using the sudo command without a password
  • How to create a new regular user with a specific username and password
  • How to revoke all privileges from the newly created user to disallow remote login

🏆 Achievements

After completing this project, you will be able to:

  • Securely create and manage user accounts in a MySQL database
  • Understand the importance of user access control in database management
  • Apply the skills learned in this project to your own database projects and administration tasks

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/TransactionManagementandSecurityGroup(["`Transaction Management and Security`"]) mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) mysql(("`MySQL`")) -.-> mysql/DatabaseFunctionsandDataTypesGroup(["`Database Functions and Data Types`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) sql(("`SQL`")) -.-> sql/DatabaseManagementandOptimizationGroup(["`Database Management and Optimization`"]) mysql/TransactionManagementandSecurityGroup -.-> mysql/identified_by("`User Authentication`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/database("`DB Function - Info Retrieval`") mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/user("`User Info Function`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("`Database Selection`") mysql/TransactionManagementandSecurityGroup -.-> mysql/revoke_permission("`Permission Revocation`") sql/DatabaseManagementandOptimizationGroup -.-> sql/security_permissions("`Security and Permissions`") subgraph Lab Skills mysql/identified_by -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/source -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/database -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/user -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} sql/select -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} sql/in -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/select -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/use_database -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} mysql/revoke_permission -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} sql/security_permissions -.-> lab-301321{{"`Creating Secure MySQL User Accounts`"}} end

Access MySQL

In this step, you will learn how to access the MySQL database using the sudo command without any password.

  1. Open a terminal on your system.
  2. Start the MySQL service by running the following command:
sudo service mysql start
  1. Access the MySQL database by running the following command:
sudo mysql

This will allow you to access the MySQL database without a password.

Create a User

In this step, you will learn how to create a regular user named Jane with a password of 123456, and disallow remote login.

  1. In the MySQL prompt, run the following SQL script:
CREATE USER 'Jane'@'localhost' IDENTIFIED BY '123456';
REVOKE ALL PRIVILEGES ON *.* FROM 'Jane'@'localhost';

This script will create a new user named Jane with the password 123456, and revoke all privileges from the user.

Verify the User Creation

In this step, you will learn how to verify that the user Jane has been created successfully.

  1. In the MySQL prompt, run the following SQL command to switch to the mysql database:
USE mysql;
  1. Run the following SQL command to view the list of users:
SELECT user, host FROM user;

This will display the list of users, including the newly created user Jane.

You should see the following output:

MariaDB [mysql]> SELECT user, host FROM user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| Jane        | localhost |
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)

Your project is now complete! You have successfully created a new user named Jane with the password 123456 and disallowed remote login.

Summary

Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.

Other MySQL Tutorials you may like