If you have an outdated or unused account in your MySQL or MariaDB database, it’s best to get rid of it. Having even one extra user is an additional vulnerability and attack surface in the database. In this guide, we’ll show you the step by the step instructions to delete a specific user from a MySQL or MariaDB database from the command line on a Linux system.
If you’ve forgotten the password to a user account and need to reset it, there’s no need to delete it and start over. We have separate guides for changing a user password in MySQL and changing the root password in MySQL.
In this tutorial you will learn:
- How to delete a user from MySQL/MariaDB database
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | MySQL, MariaDB |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Deleting a user
Open a terminal on your system and follow these steps to delete a user from MySQL or MariaDB:
- Open MySQL as the root user.
$ mysql -u root -p OR $ sudo mysql
- Next, use the
DROP USER
command to delete a user. In this example, we’re deleting userlinuxconfig
.mysql> DROP USER 'linuxconfig'@'localhost';
Assuming the user exists, MySQL should issue a Query OK
response, and the user is no longer in the database. You can now exit the MySQL terminal with the exit
command.
Conclusion
Deleting a user in MySQL or MariaDB is quick and easy, as we saw in this guide. Keeping a minimal number of users will keep your database more secure against attacks.