A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sql/mysql-drop-user/ below:

MySQL | DROP USER - GeeksforGeeks

MySQL | DROP USER

Last Updated : 10 Sep, 2024

In MySQL, managing user accounts is essential for database security and proper access control. The DROP USER statement is a powerful tool used by database administrators to delete user accounts that are no longer required.

This command ensures that all privileges assigned to the user are revoked, preventing them from accessing the MySQL server. In this article, We will learn about MySQL DROP USER in detail by understanding various examples and so on.

MySQL DROP USER

Syntax:

DROP USER 'username'@'host';

Parameters:

Example of MySQL DROP USER

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:

Example 1: Dropping a single user using the DROP USER statement Dropping a Single User:

To delete a single user account, such as gfguser1, the following query is executed:

Query:

DROP USER 'gfguser1'@'localhost';

Output:

Explanation: This will remove the user gfguser1 from the MySQL server, and the user will no longer be able to log in or access the database.

Example 2: Dropping multiple users using the DROP USER statement Dropping Multiple Users:

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' , DROP USER 'gfguser2'@'localhost';

Output:

Explanation: This query drops both users in one step, revoking their access to the MySQL serv

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.

Conclusion

The DROP USER statement in MySQL is an essential command for effectively managing and controlling user access within the database. Whether you are removing an individual user or cleaning up multiple accounts, it simplifies the process of user management by revoking privileges and preventing access after the account is dropped. Database administrators can use this command to ensure a more secure and organized database environment.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4