The DROP USER statement in MySQL can be used to remove a user account along with its privileges from the MySQL completely.But before using the drop user statement, the privileges of the user should be revoked or in other words, if a user has no privileges then the drop user statement can be used to remove a user from the Mysql database server.
DROP USER 'user'@'host';
1. User:It is the user name of the user account you want to drop.
2. Host:It is the host server name of the user account.The user name should be in the following format
Suppose there are 4 users in the MySQL database server as listed below:
We can drop a single user account as well as multiple user accounts using a single DROP USER statement as shown below:
Dropping a single user using the DROP USER statement: To drop the user account with the username “gfguser1”, the drop user statement should be executed as follows:
Table after execution of the drop user statement will be as follows:
Dropping multiple users using the DROP USER statement: The Drop User statement can be used to drop multiple user accounts at once. To drop two user account “gfguser2” and “gfguser1” from the table mentioned above,the drop user statement should be executed as follows:
Table after execution of the above drop user statement will be as follows:
Note: In case the DROP USER statement is executed for an user account when the session for this account is active then it will not effect that account until it’s session gets closed. The user account will be dropped after its session gets closed and will not be able to login any more.
- MySQL | USER( ) Function
- MySQL | RENAME USER
- MySQL | CREATE USER Statement
- MySQL | Change User Password
- Mysql | User-defind Variables
- MySQL | Common MySQL Queries
- SQL | DROP, TRUNCATE
- SQL | ALTER (ADD, DROP, MODIFY)
- Difference between DROP and TRUNCATE in SQL
- Difference between DELETE and DROP in SQL
- Difference between DELETE, DROP and TRUNCATE
- MySQL | IF( ) Function
- How to get ID of the last updated row in MySQL?
- MySQL | MD5 Function
- MySQL | BIN() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.