![]() |
VOOZH | about |
Managing user accounts in MySQL is important for maintaining database security and controlling access to the server. The DROP USER statement allows administrators to remove user accounts that are no longer required.
Syntax:
DROP USER 'username'@'host';
The following examples demonstrate how the DROP USER statement works in MySQL and how it can be used to delete single or multiple user accounts from the MySQL server. Suppose there are 4 users in the MySQL database server as listed below:
👁 ImageA single DROP USER statement can be used to delete one or multiple user accounts.
To delete a single user account, such as gfguser1, the following query is executed:
Query:
DROP USER 'gfguser1'@'localhost';Output:
👁 ImageThis command removes the gfguser1 account from the MySQL server, and the user will no longer be able to log in or access the database.
Multiple user accounts can be deleted simultaneously using a single DROP USER statement. For example, to remove both gfguser1 and gfguser2:
Query:
DROP USER 'gfguser1'@'localhost' , 'gfguser2'@'localhost';Output:👁 Image
This query drops both users in one step, revoking their access to the MySQL server.
Note: If a DROP USER command is executed while the user session is active, the account is removed only after the session ends, and the user cannot log in again.