In this MariaDB Tutorial, Let us see, how to remove user in MariaDB. Here we will see a few examples on the related topics.
MariaDB Remove User
Here, you will learn how to remove a user in MariaDB with syntax and examples.
For this, you need to use the DROP USER statement, which is used to remove a user.
The syntax for the DROP USER statement is as follows.
DROP USER user_name;
Here, the user_name is the user name you want to remove from MariaDB.
The steps to remove a user from MariaDB are as follows.
1. First, you must look at all the users by typing the following command.
SELECT User FROM mysql.user;
Select any user from the list you want to remove from MariaDB.
2. Now, you must type the following command to remove the user you want.
DROP USER 'James'@'localhost';

3. The selected users have been removed, but to ensure the proper completion of the task, you can type the following command to list all the users.
SELECT User FROM mysql.user;

The user James is not present in the list of all users, which ensures that the process has been completed successfully.
Note – You can also remove more than one user by using the following command.
DROP USER 'Natasha'@'localhost', 'Tony'@'localhost';
And make sure you flush the privilege using the following command.
FLUSH PRIVILEGES;

This is how you can remove Users from MariaDB.
Read How to create a user in MariaDB
MariaDB Remove User Password
Let us show you how to remove user passwords in MariaDB.
You can change the password instead of removing it by using ALTER statement due to security reasons.
You can change the password by typing the following command.
ALTER USER 'Ross'@'localhost' IDENTIFIED BY 'ross456';
Your password will be changed.
And make sure you flush the privilege using the following command.
FLUSH PRIVILEGES;

Read How to Create Database in MariaDB
MariaDB Remove User Grants
Here, you will learn how to remove user grants using the REVOKE statement. This statement enables system administrators to revoke MariaDB privileges (or roles).
The syntax for removing user grants using the REVOKE statement is as follows.
REVOKE ALL PRIVILEGES, GRANT OPTION FROM user 'Username'@'localhost';
Here, the Username is the name of the user whose privileges you want to revoke.
Note—If a user has remote access, you can use ‘%‘ instead of ‘localhost’.
For example, you can remove user grants using the following command.
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'Sophia'@'localhost';

Here, Sophia is the name of the user.
Read How to Grant User Access to a MariaDB Database
MariaDB Remove User From Database
This article uses syntax and examples to explain how to remove a user from a database in MariaDB.
You need to use the DROP USER statement, which removes a user from a database.
The syntax for the DROP USER statement is as follows.
DROP USER user_name;
The user_name is the user name you want to remove from MariaDB.
The steps to remove a user from MariaDB are as follows.
1. First, you must look at all the users by typing the following command.
SELECT User FROM mysql.user;
Select any user from the list you want to remove from MariaDB.
2. Now, you must type the following command to remove the user you want.
DROP USER 'Katherine'@'%';
Here, ‘%‘ is used in place of ‘localhost‘ as the user, i.e., Katherine is a user with remote access.
3. The selected user have been removed, but to ensure the proper completion of the task, you can type the following command to list all the users.
SELECT User FROM mysql.user;

Katherine is not present in the list of all users, ensuring the process has been completed successfully.
Note – You can also remove more than one user by using the following command.
DROP USER 'Chris'@'localhost', 'Caroline'@'localhost';
And make sure you flush the privilege tables using the following command.
FLUSH PRIVILEGES;

Read How to Create Table in MariaDB
MariaDB Remove Anonymous Users
MariaDB includes an Anonymous User account that allows anyone to connect to the MariaDB server without having a user account created for them.
It is intended only for testing and to make installation a bit smoother, but it should be removed before moving towards a production environment.
Here, you can remove the anonymous user by typing the following command.
DELETE FROM mysql.user WHERE User='';
Now, all the anonymous users will be deleted.
And make sure you flush the privilege using the following command.
FLUSH PRIVILEGES;

Read How to Add Column in MariaDB
MariaDB Remove All Users
In this, you will learn how to remove all users in MariaDB.
You can remove all the users by using the DROP statement, and commas separate the names of all users.
The syntax for removing multiple users at once is as shown below.
DROP USER 'user1'@'localhost', 'user2'@'localhost',......;
You can remove all the users using this method.
MariaDB Remove Root User
In this, you will learn how to remove root user in MariaDB.
Removing the root user will throw connection refused errors, resulting in the server malfunctioning. So, it is suggested that the root user not be removed. Even if you want to remove it for experimental purposes, you can create a new user with all the privileges of the root user.
For this, you need to use the DROP USER statement to remove the root user.
DROP USER 'root'@'localhost';
Now, the root user will be deleted.
And make sure you flush the privilege tables using the following command.
FLUSH PRIVILEGES;
Read How to Grant All Privileges in MariaDB
MariaDB Remove User ERROR 1396
In this, we will learn about ERROR code 1396 related to removing users’ accounts.
ERROR 1396 usually occurs when it fails to execute statements related to user management, such as CREATE USER or DROP USER.
It occurs during the Drop statement when the user we want to delete does not exist in MariaDB.
For example, you can try to remove a user named Jack or any other user who does not exist in the Users list.
DROP USER 'Jack'@'localhost';

Here, you can see the ERROR 1396 as the user i.e. Jack does not exist.
You may like the following MariaDB tutorials:
- How to Create View in MariaDB
- MariaDB Truncate Table + Examples
- Replace Function in MariaDB
- How to import CSV files in MariaDB
- MariaDB Union Operator
- MariaDB Timestamp
- MariaDB Set Variable
- MariaDB ERROR 1064
In this MariaDB Tutorial, we have learned the quick steps to remove user MariaDB.
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.