1. Home
  2. Articles
  3. Courses
    1. Articles
  4. Community
  5. Definitions
  6. Files
    1. Terms Of Condition
  • Login
  • Register
  • Search
Course Articles
  • Everywhere
  • Articles
  • Pages
  • Forum
  • Definitions
  • Course Articles
  • Filebase Entry
  • More Options
  1. Scientific Tools
  2. Courses
  3. MySQL Guides

User Management MySQL: Guide to Create, Manage and Permissions

  • ScientificTools.org
  • November 27, 2023 at 4:22 PM
  • 1,106 times read
Contents [hideshow]
  1. Understanding User Management in MySQL
  2. Creating and Managing Users
    1. Creating a New User
    2. Setting Passwords
    3. Deleting Users
  3. Granting and Revoking Permissions
    1. Granting Permissions
      1. Granting Database-Specific Privileges
      2. Granting All Privileges
    2. Revoking Permissions
      1. Revoking Specific Privileges
      2. Revoking All Privileges
    3. Applying Changes
  4. Using Roles for Managing Permissions
    1. Creating Roles
    2. Granting Privileges to a Role
    3. Assigning Roles to Users

Managing users and their privileges in MySQL is critical to database security and efficiency. In this guide, we will cover the basics of creating and managing users, as well as granting and revoking privileges, with practical examples.

Understanding User Management in MySQL

User management in MySQL involves creating user accounts, assigning specific privileges, and ensuring secure access to the database.

Creating and Managing Users

User creation in MySQL involves defining a username, host, and password.

What is localhost ?

Creating a New User

Code
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
  • CREATE USER: This command creates a new user.
  • 'new_user'@'localhost': Here, 'new_user' is the username, and 'localhost' specifies that the user can connect from the local machine. For remote access, replace 'localhost' with an IP address or %.
  • IDENTIFIED BY 'password': Sets the user’s password. Replace 'password' with a secure password.

Setting Passwords

Code
ALTER USER 'new_user'@'localhost' IDENTIFIED BY 'new_password';
  • ALTER USER: Modifies an existing user.
  • 'new_password': The new password for the user.

Deleting Users

Code
DROP USER 'new_user'@'localhost';
  • DROP USER: Removes a user account from MySQL.
  • This command deletes the 'new_user' account.

Granting and Revoking Permissions

Permissions define what actions a user can perform in the database.

Granting Permissions

Granting Database-Specific Privileges

Code
GRANT SELECT, INSERT ON mydb.* TO 'new_user'@'localhost';
  • GRANT: Assigns specific privileges.
  • SELECT, INSERT: Types of privileges. SELECT allows reading data; INSERT permits adding data.
  • mydb.*: Applies privileges to all tables (*) in the mydb database.

Granting All Privileges

Code
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost';
  • Grants all available privileges on all databases and tables.

Revoking Permissions

Revoking Specific Privileges

Code
REVOKE INSERT ON mydb.* FROM 'new_user'@'localhost';
  • REVOKE: Removes specific privileges.
  • Removes the INSERT privilege from new_user on mydb.

Revoking All Privileges

Code
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'new_user'@'localhost';
  • Removes all privileges from the user.

Applying Changes

Code
FLUSH PRIVILEGES;
  • Refreshes MySQL’s memory to apply the privilege changes.

Using Roles for Managing Permissions

Roles in MySQL are named collections of privileges, simplifying privilege management.

Creating Roles

Code
CREATE ROLE 'manager';
  • CREATE ROLE: Creates a new role, here named 'manager'.

Granting Privileges to a Role

Code
GRANT SELECT, INSERT ON mydb.* TO 'manager';
  • Assigns SELECT and INSERT privileges to the 'manager' role for the mydb database.

Assigning Roles to Users

Code
GRANT 'manager' TO 'new_user'@'localhost';
  • Grants all privileges associated with the 'manager' role to 'new_user'.
  • Previous Article Guide to Views in MySQL: Creating Updating Deleting
  • Next Article How to secure and harden MySQL

Categories

  • MySQL

Archive

  1. 2023 (33)
    1. November (27)
      • Guide to MySQL IN and NOT IN Operators
      • Guide to MySQL OR Operator
      • Guide to MySQL AND Operator
      • Guide to MySQL DISTINCT Clause
      • MySQL SELECT FROM Statement Guide
      • What is EXPLAIN statement in MySQL and what it does ?
      • Guide to Query Caching in MySQL
      • How to Optimize MySQL Queries?
      • Guide to Entity-Relationship (ER) Diagrams in MySQL with Examples
      • What is Normal Forms and Normalization in MySQL
      • How to design a MySQL database with high performance
      • Principals of Secure Database Design in MySQL
      • How to secure and harden MySQL
      • User Management MySQL: Guide to Create, Manage and Permissions
      • Guide to Views in MySQL: Creating Updating Deleting
      • Guide to Stored Procedures and Functions in MySQL
      • Guide to Indexes in MySQL: Creating and Managing Indexes
      • Advanced Filtering in MySQL guide and examples
      • Practical guide for UNION and UNION ALL in MySQL with examples
      • Joining Tables in MySQL guide with examples
      • Guide to GROUP BY and HAVING clauses in MySQL with examples
      • MySQL ORDER BY Clause guide with practical examples
      • Complete MySQL WHERE Clause guide with examples
      • What is a MySQL subquery and how are subqueries executed in MySQL?
      • How to do queries in MySQL
      • How to create, modify, rename and delete tables using MySQL
      • MySQL CRUD Operations (Create, Read, Update, Delete)
    2. October (2)
    3. August (2)
    4. July (2)
  1. Privacy Policy
  2. Legal Notice
Copyright© ScientificTools.org 2026. All rights reserved.
All the content posted on this website are licenses by MySecure Space GmbH under Creative Commons CC BY-NC-ND 4.0
Creative Commons CC BY-NC-ND 4.0
Developed & Hosted by: MySecure.Space | Powered by: WoltLab Suite™