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 -pThe 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 VPS hosting, cloud 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.
Ronald Caldwell