Remove a MySQL User on Linux via Command Line

Posted on by Ronald Caldwell | Updated:
Reading Time: 2 minutes

System administrators do well to further their security practices by removing users from MySQL who no longer require access. They should ensure that they get released as users change, and turnover happens. It provides security and safeguards against unlawful access to data.

This tutorial walks you through how to remove a MySQL user on Linux using the command line.

Prerequisites

  • A server running CentOS or AlmaLinux.
  • Root access and log in as the root user.
  • Access to the terminal.
  • Basic command line knowledge.
How to Remove a MySQL User on Linux via Command Line

How to Remove a MySQL User on Linux via Command Line

Step 1: Access the MySQL Server

Using the following command, access the MySQL server from the command line. This command specifies the root user with the -u flag. The -p flag makes MySQL prompt for a password. Enter your current password to complete the login.

mysql -u root -p

The system shows the MySQL prompt. You can create users in MySQL or change a user password for the root or any other database user.

mysql>

Step 2: View a List of MySQL Users

The following statement allows you to view a complete list of MySQL users, including their associated host.

SELECT User,Host FROM mysql.user;

Step 3: Remove a MySQL User

To remove a user from MySQL, use the DROP command. Be advised that dropping a user cannot be undone. The following command removes the user testuser.

DROP USER 'testuser'@'localhost';

If a user of the name testuser does not exist, you'll receive an error.

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

Refer to step 2 if you receive the error, and double-check the username and host. Repeat the DROP command to remove the user once you confirm the appropriate username and host.

Wrapping Up

It is easy to remove a MySQL user in Linux from the command line. These commands allow for accomplishing this task quickly. Removing a MySQL user on Linux via command line is another security measure administrators must take to secure data systems consistently.

Liquid Web customers on fully managed VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers have 24/7/365 support for these and other functions. Contact our sales team today to ensure you get the environment you need.

Avatar for Ronald Caldwell

About the Author: Ronald Caldwell

Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.

Latest Articles

Controlling PHP settings with a custom php.ini file

Read Article

How to install Puppet Server on Linux (AlmaLinux)

Read Article

Email security best practices for using SPF, DKIM, and DMARC

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article