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.
- 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
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.
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.
- Using MySQL Command Line to Create a User
- 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
- Delete a MySQL or MariaDB Database via Command Line
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.