Remove a MySQL User on Linux via Command Line
MySQL via Command Line 101: Basic Database Interaction
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
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.
Related Articles:
- How to Use Disk Quotas in Dedicated Linux Servers With cPanel
- How to Use Disk Quotas in Dedicated Linux Servers with Plesk
- Remove Permissions for a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line
- Using MySQL Command Line to Create a User
- Delete a MySQL or MariaDB Database via Command Line
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.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Force HTTPS For Your Domain
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article