Summary: in this tutorial, you will learn how to use the MySQL DROP USER
statement to remove one or more user accounts from the database.
Introduction to MySQL DROP USER
statement
To remove a user account from the MySQL Server, you use the DROP USER
statement as follows:
In this syntax, you specify the name of the user account that you want to remove after the DROP USER
keywords.
If you want to remove multiple user accounts at once, you specify a list of comma-separated user accounts in the DROP USER
clause:
If you remove a user account that doesn’t exist, MySQL will issue an error.
In MySQL 5.7.8+, you can use the IF EXISTS
clause to conditionally drop a user only if it exists:
Besides removing the user account, the DROP USER
statement also removes all privileges of the user from all grant tables.
MySQL DROP USER
examples
Let’s take some examples of dropping users.
A) Using MySQL DROP USER
statement to drop a user example
First, connect to the MySQL Server using the root
account:
Type the password for the root
user and press Enter
:
Second, create four account users accounts api@localhost
, remote
, dbadmin@localhost
and…