How to change root password for MySQL

I will give an example of changing the root password for MySQL.

Connect to the MySQL server:

mysql -u root -p

Let’s see what users are (as there may be several root users with different hosts):

select * from mysql.user;
select user,host from mysql.user;

Suppose there is only one “root’@’localhost”, then change the password to it:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Done, the password is changed, now we’ll exit the MySQL console:


See also my articles:
How to reset root password for MySQL
How to create a MySQL user and configure access rights

Leave a comment

Leave a Reply