Last Updated: 28 June, 2023
To drop a user in MySQL, we can use the DROP USER statement. Here's the syntax:
DROP USER 'username'@'hostname';
Replace 'username' with the name of the user we want to drop and 'hostname' with the host from which the user is allowed to connect. If the user can connect from any host, we can use '%' as the hostname.
For example, to drop a user named 'shweta' that can connect from any host, we would execute the following command:
DROP USER 'shweta'@'%';
Please note that dropping a user will permanently remove the user and revoke all privileges granted to that user. Exercise caution when using this command.
The IF EXISTS clause is optional and allows us to avoid an error if the user doesn't exist.
DROP USER IF EXISTS 'username'@'hostname';
If we want to drop multiple users in a single DROP USER statement, we can provide their names separated by commas. Let's see the example below.
DROP USER 'username1', 'username2', 'username3';
Please note that we need appropriate privileges (e.g., DROP USER) to execute this command, typically granted to administrative users like the "root" user.
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com