1. Log in to your MySQL server as the root user:
mysql -u root -p
2. List all users:
SELECT User, Host FROM mysql.user;
3. Delete a user:
DROP USER ‘username’@’host’;
4. Flush the privileges:
FLUSH PRIVILEGES;
To remove or delete user MySQL command line Linux; In this tutorial, you will learn step by step on how to delete or remove user from MySQL database in Linux.
MySQL stores account names in grant tables in the mysql system database using separate columns for the user name and host name parts: The user table contains one row for each account. The User and Host columns store the user name and host name. This table also indicates which global privileges the account has.
To delete a MySQL user is to remove an account and its privileges from all grant tables. Only users with global CREATE USER or DELETE privileges can perform such tasks. In this tutorial, learn how to delete MySQL user accounts using the DROP USER statement.
Prerequisites for access denied for How To Delete or Remove a MySQL User Account on Linux:
- Access to a command line or terminal
- MySQL or MariaDB installed
- User with sudo or root privileges
How To Delete or Remove a MySQL User Account on Linux Ubuntu
Use the following steps to delete user in mysql ubuntu using command line:
- Step 1 – Login as Root user MySQL
- Step 2 – Find user in MySQL
- Step 3 – Delete Remove User in MySQL
- Step 4 – Check MySQL User
Step 1 – Login as Root user MySQL
Installed MySQL and try to access phpmyadmin on the local/server machine with the root user, the command you use is:
mysql -u root -p
In most cases, you will receive the error message Access denied for user ‘root’@’localhost’.
You can enable access for root using one MySQL command.
To be able to log into MySQL as root, first use sudo
to modify the root user:
sudo mysql
Enter your password at the prompt. A MySQL shell loads.
Step 2 – Find user in MySQL
Execute the following command on terminal to find the exact name of the user you want to remove by running a command that lists users from the MySQL server:
SELECT User, Host FROM mysql.user;
The above command will displays all users.
Step 3 – Delete Remove User in MySQL
Before exeucte the following command, Replace username in the following command with your user:
DROP USER '<em>username</em>'@'host';
Step 4 – Check MySQL User
Execute the following command on terminal recheck the user list to verify the user was deleted:
SELECT User, Host FROM mysql.user;
Conclusion
In this tutorial, you have learned how to solve access denied for user ‘root’@’localhost’ (using password yes) mysql phpmyadmin ubuntu 18.04/20.04.