How to Delete or Remove Users MySQL Command line on Linux

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.

Recommended Linux/Ubuntu Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *