How to remove a MySQL/MariaDB user

How to remove a MySQL/MariaDB user

Colleagues hello to all.

In today's article, I'll tell you how to correctly delete a user from a Mysql database. If you have outdated or accounts in your database it's best to get rid of them. Having even one unnecessary user is an additional vulnerability and an opportunity for an attacker to attack your database.

 

First, we need to review all the users in our Mysql database to determine which user we no longer need. To revise users you can use sql query:

mysql> SELECT user, host FROM mysql.user;

mysql delete user

As a result, the database will show us all the users that exist in our Mysql database.


 

For example, today we will be deleting the user application. You can of course delete it right away, but it is considered good practice to start checking its rights. To view user rights, use the sql query:

mysql> SHOW GRANTS FOR 'application'@'%';

mysql delete user

As you can see, the user has no particular rights.


 

If the user has any rights, then first they need to be removed, for this we will use the sql query:

mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'application'@'%';

mysql delete user

This command will remove absolutely all the rights that the user has.


 

Now that we have decided which user we will delete and stripped him of all rights in the database, now we can safely delete him. To delete, use the sql query:

mysql> DROP USER 'application'@'%';

mysql delete user

User deleted successfully!


 

Now we need to execute the sql command, which resets the cache on the table with users and the table permissions.

mysql> FLUSH PRIVILEGES;

mysql delete user


 

So, colleagues in today's article, we got to know how to correctly delete users from the Mysql database, this approach will also work for Mariadb.

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

MySQL - Test Data Generation
MySQL - Test Data Generation
MYSQL
Read more
MySQL / MariaDB How to get the id of the last inserted record in a table - LAST_INSERT_ID
MySQL / MariaDB How to get the id of the last inserted record in a table - LAST_INSERT_ID
MYSQL
Read more
MySQL/MariaDB How to convert character case - UPPER and LOWER functions
MySQL/MariaDB How to convert character case - UPPER and LOWER functions
MYSQL
Read more