Skip to main content
wpcrux.com

Back to all posts

How to Create And Manage Users In MySQL?

Published on
3 min read
How to Create And Manage Users In MySQL? image

Best MySQL User Management Tools to Buy in October 2025

1 High Performance MySQL: Optimization, Backups, Replication, Load Balancing & More (Advanced Tools and Techniques for MySQL Administrators)

High Performance MySQL: Optimization, Backups, Replication, Load Balancing & More (Advanced Tools and Techniques for MySQL Administrators)

BUY & SAVE
$27.99
High Performance MySQL: Optimization, Backups, Replication, Load Balancing & More (Advanced Tools and Techniques for MySQL Administrators)
2 Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

BUY & SAVE
$30.15 $49.99
Save 40%
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)
3 Murach's MySQL

Murach's MySQL

  • MASTER ESSENTIAL SQL STATEMENTS FOR MYSQL DATABASE CREATION.
  • HANDS-ON CODING EXAMPLES FOR REAL-WORLD DATABASE APPLICATIONS.
  • BOOST YOUR CAREER WITH IN-DEMAND SQL SKILLS AND KNOWLEDGE.
BUY & SAVE
$79.13
Murach's MySQL
4 Head First PHP & MySQL: A Brain-Friendly Guide

Head First PHP & MySQL: A Brain-Friendly Guide

BUY & SAVE
$17.43 $54.99
Save 68%
Head First PHP & MySQL: A Brain-Friendly Guide
5 Linux Server Hacks: 100 Industrial-Strength Tips and Tools

Linux Server Hacks: 100 Industrial-Strength Tips and Tools

  • QUALITY ASSURANCE: ALL BOOKS ARE CHECKED FOR GOOD CONDITION.
  • ECO-FRIENDLY CHOICE: SUPPORT SUSTAINABILITY BY BUYING USED BOOKS.
  • GREAT DEALS: SAVE MONEY WITH AFFORDABLE PRICES ON QUALITY READS.
BUY & SAVE
$11.34 $24.95
Save 55%
Linux Server Hacks: 100 Industrial-Strength Tips and Tools
6 Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL

BUY & SAVE
$19.90
Build a real Search Engine: Engineering tools: HTML, CSS, JavaScript, PHP, MySQL
7 MySQL Crash Course

MySQL Crash Course

BUY & SAVE
$20.00 $34.99
Save 43%
MySQL Crash Course
8 MySQL Cookbook

MySQL Cookbook

  • AFFORDABLE PRICES FOR QUALITY READS-GREAT VALUE FOR BUDGET SHOPPERS!
  • ECO-FRIENDLY CHOICE: SUPPORT RECYCLING WHILE ENJOYING GREAT STORIES!
  • THOROUGHLY VETTED CONDITION ENSURES RELIABLE, ENJOYABLE READING EXPERIENCE.
BUY & SAVE
$29.95 $49.99
Save 40%
MySQL Cookbook
9 AWS Lightsail setup, tricks and tools: DNS Zones, PHP, mySQL, SSL Cert, VHosts, metric, bots and all you need to succeed

AWS Lightsail setup, tricks and tools: DNS Zones, PHP, mySQL, SSL Cert, VHosts, metric, bots and all you need to succeed

BUY & SAVE
$9.99
AWS Lightsail setup, tricks and tools: DNS Zones, PHP, mySQL, SSL Cert, VHosts, metric, bots and all you need to succeed
10 MySQL High Availability: Tools for Building Robust Data Centers

MySQL High Availability: Tools for Building Robust Data Centers

BUY & SAVE
$42.99
MySQL High Availability: Tools for Building Robust Data Centers
+
ONE MORE?

To create and manage users in MySQL, you need to have administrative privileges or the "CREATE USER" privilege.

To create a new user, you can use the "CREATE USER" statement followed by the username and password. Here is an example:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

You can replace 'username' with the desired username for the user and 'password' with the desired password.

To assign specific privileges to the user, you can use the "GRANT" statement. For example, to grant all privileges on a specific database to the user, you can use the following command:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

Replace 'database_name' with the actual name of the database you want to grant access to. The keyword "ALL PRIVILEGES" grants all available privileges, but you can also specify specific privileges such as "SELECT," "UPDATE," or "DELETE."

If you want to remove privileges from a user, you can use the "REVOKE" statement. For example:

REVOKE ALL PRIVILEGES ON database_name.* FROM 'username'@'localhost';

To delete a user completely, you can use the "DROP USER" statement followed by the username:

DROP USER 'username'@'localhost';

Remember to substitute 'username' with the actual username you wish to delete.

Lastly, you can view all existing users within MySQL using the following command:

SELECT User, Host FROM mysql.user;

This will show you a list of active users and their corresponding hostnames.

How to revoke privileges from a user in MySQL?

To revoke privileges from a user in MySQL, you can use the REVOKE statement. Here is the syntax to revoke privileges from a user:

REVOKE privilege_type [, privilege_type]... ON database_name.table_name FROM user_name [IDENTIFIED BY 'password']

Here's what each component means:

  • privilege_type: The privilege or privileges you want to revoke. Some common privileges include SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, and GRANT OPTION.
  • database_name.table_name: The specific database and table you want to revoke privileges from. If you want to revoke privileges from all databases, you can use *.*.
  • user_name: The name of the user you want to revoke privileges from.
  • IDENTIFIED BY 'password': Optional. If the user has a specific password set, you may need to include this clause and specify the password.

Example:

Let's say you want to revoke the SELECT and INSERT privileges from the user "testuser" on the "mydatabase" database. The syntax would be:

REVOKE SELECT, INSERT ON mydatabase.* FROM testuser;

This will revoke the SELECT and INSERT privileges from the specified user on the specified database.

What is the command to display the current user in MySQL?

The command to display the current user in MySQL is:

SELECT USER();

How to show the current user in MySQL?

To show the current user in MySQL, you can use the following SQL command:

SELECT USER();

This will retrieve the currently logged-in user in the current MySQL session.