MySQL Remove User

In this MySQL tutorial, we will look at how to remove a user and their corresponding privileges from a MySQL database. If you recall, before being able to log in to the MySQL server, you must have a username and a corresponding password.

The administrator for the MySQL server would have created users and granted the appropriate permissions to these users. When a user is no longer needed on the system, it is best practice to remove this user from the system to remove potential points of database infiltration.

To remove a MySQL user, we use the DROP USER statement.

MySQL Drop User Systax

The syntax for the MySQL Drop User statement is as follows:

DROP USER username;

Since MySQL server version 5.0.2, it is possible to remove a user account and its privileges at the same time using the DROP USER command. Before that you would have to remove privileges before removing the user itself.

MySQL Drop User Example

To remove a user called "guest" which was permitted to log in from "localhost", we would do it as follows:

DROP USER 'guest'@'localhost';

Note that when removing a user, we need to know where they were permitted to log in from (their hostname) when they were created. Otherwise, removing the user will not work.

If only a username is specified, the hostname of '%' is assumed.

That is:

DROP USER 'james';

Is treated as:

DROP USER 'james'@'%';

As with any delete command, be careful when using it. Ensure that the user you are trying to remove is no longer needed on the system before deleting their account. Otherwise, you may have dissatisfied users, or possibly web applications that cannot access their database.

We hope this MySQL remove user tutorial was useful.

Link to this Page

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...