Remove a MySQL User on Linux via Command Line

Login to MySQL

First we’ll login to the MySQL server from the command line with the following command:

mysql -u root -p


In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.

If you need to change your root (or any other) password in the database, then please do so first!

You should now be at a MySQL prompt that looks very similar to this:

mysql>


View a List of MySQL Users

Viewing a full list of MySQL users, including the host they’re associated with, can be done with the following select statement:

SELECT User,Host FROM mysql.user;


Remove a MySQL User

To remove a user from MySQL, we again use the DROP command.

It only takes one simple command to delete a user in MySQL, but BEWARE; dropping a user can not be undone! The command is as follows:

DROP USER 'testuser'@'localhost';


If a user of the name testuser does not exist, then you’ll receive this error:

ERROR 1396 (HY000): Operation DROP USER failed for 'testuser'@'localhost'


Refer to the View a List of MySQL Users section above if you receive the above error, and double check the username and host.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Use httpd fullstatus to Monitor Apache Status

Sometimes checking server performance can be difficult. Apache has built in utilities that help...

How to Install Logwatch on CentOS 7

Logwatch is a Perl-based log management tool for analyzing, summarizing, and reporting on a...

How to Check Your Ubuntu Version

The following command works with all Ubuntu versions. lsb_release -a You should receive a...

How to Check the glibc (GNU libc) Version on Fedora 20 and Fedora 21

Using ldd ldd --version This should return a result similar to (though your version may vary):...

How to Install the Xfce Desktop Environment on Ubuntu 14.04 LTS

By default XWeb servers running Ubuntu 14.04 don’t include a graphical desktop environment. It’s...

Powered by WHMCompleteSolution