Skip to content

The best way to delete a user in MySQL is with the DROP USER command. This post walks you through it.

Understanding the DROP USER Command

The DROP USER command is used to remove one or more MySQL user accounts and their privileges.

Syntax

DROP USER [IF EXISTS] user_name@host_name;
  • IF EXISTS: Optional clause to prevent an error from occurring if the user does not exist.
  • user_name@host_name: Specifies the username and the host from which they connect. The host name can be a specific IP, % for any host, or omitted for the default host.

How to Remove a Single User

To remove a specific user, use the following command, replacing username and hostname with the appropriate values:

DROP USER username@hostname;

How to Remove Multiple Users

To delete multiple users in a single command, separate each user by a comma:

DROP USER user1@host1, user2@host2;

Using IF EXISTS

If you’re unsure whether a user exists, you can use IF EXISTS to avoid errors:

DROP USER IF EXISTS username@hostname;

Revoke Privileges Before Deletion

You should probably revoke all of the user’s privileges before deleting them. That way they’ll lose access even if, for whatever reason, the deletion command fails.

REVOKE ALL PRIVILEGES, GRANT OPTION FROM username@hostname;
DROP USER username@hostname;

Flush Privileges

After deleting a user, it’s important to run the FLUSH PRIVILEGES command. This will make sure the changes are applied immediately.

FLUSH PRIVILEGES;

Check Existing Users

Before deletion, you may want to check the existing users. Use the following command:

SELECT User, Host FROM mysql.user;

For access management workflows, Basedash complements SQL controls with governed reporting, shared visibility, and AI-assisted analysis so teams can monitor permission changes without losing auditability.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.