MySQL | DROP USER
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.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
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.
- https://dev.mysql.com/doc/refman/5.7/en/drop-user.htmlMy Personal Notes arrow_drop_up