Number of Users with Modify Permissions

SQLSQLBeginner
Practice Now

Introduction

In this project, you will learn how to retrieve the number of users with modify permissions from the user table in a MySQL database.

👀 Preview

Unfinished

🎯 Tasks

In this project, you will learn:

  • How to start and log in to the MySQL terminal
  • How to switch to the mysql database and query the number of users with modify permissions
  • How to save the SQL statement to a file
  • How to run the SQL script to display the result

🏆 Achievements

After completing this project, you will be able to:

  • Understand how to interact with a MySQL database using the MySQL terminal
  • Write SQL queries to retrieve specific information from database tables
  • Save SQL statements to a file and execute them
  • Apply your MySQL knowledge to solve real-world problems involving user permissions

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) sql(("`SQL`")) -.-> sql/AdvancedDataOperationsGroup(["`Advanced Data Operations`"]) sql(("`SQL`")) -.-> sql/DatabaseManagementandOptimizationGroup(["`Database Management and Optimization`"]) mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/where("`WHERE clause`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("`Database Selection`") sql/AdvancedDataOperationsGroup -.-> sql/numeric_functions("`Numeric functions`") sql/DatabaseManagementandOptimizationGroup -.-> sql/using_indexes("`Using Indexes`") subgraph Lab Skills mysql/source -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} sql/select -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} sql/where -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} sql/in -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} mysql/select -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} mysql/use_database -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} sql/numeric_functions -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} sql/using_indexes -.-> lab-301366{{"`Number of Users with Modify Permissions`"}} end

Start MySQL and Log In

In this step, you will learn how to start MySQL and log in to the MySQL terminal.

  1. Create the showNum.sql file in the ~/project directory:

    touch ~/project/showNum.sql
  2. Start MySQL:

    sudo /etc/init.d/mysql start
  3. Log into the MySQL terminal:

    mysql -uroot

    You are now in the MySQL terminal, where you can enter MySQL commands.

Switch to the MySQL Database and Query the Number of Users With Modify Permissions

In this step, you will learn how to switch to the mysql database and query the number of users with modify permissions.

  1. Switch to the mysql database:

    USE mysql;
  2. Query the number of users with modify permissions:

    SELECT COUNT(*)
    FROM mysql.user
    WHERE Update_priv = 'Y';

    This query will return the number of users with modify permissions.

Save the SQL Statement to a File

In this step, you will learn how to save the SQL statement to a file.

  1. Open the showNum.sql file in a text editor and add the following SQL statement:

    USE mysql;
    SELECT COUNT(*)
    FROM mysql.user
    WHERE Update_priv = 'Y';

    Save the file.

Run the SQL Script

In this step, you will learn how to run the SQL script.

  1. In the MySQL terminal, run the showNum.sql script:

    SOURCE ~/project/showNum.sql;

    This will execute the SQL statement in the showNum.sql file and display the result.

    Example output:

    MySQL [mysql]> SOURCE ~/project/showNum.sql;
    +----------+
    | count(*) |
    +----------+
    |        2 |
    +----------+
    1 row in set (0.000 sec)

    The output shows that there are 2 users with modify permissions in the mysql database.

✨ Check Solution and Practice

Summary

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

Other SQL Tutorials you may like