MySQL change root password. Find root username

761 Views Asked by At

I am a beginner and I have two servers. One is Debian based and one is CentOS based.

I tried lots of methods (listed below) and from other websites but I didn't find how to change the root password of MySQL or even to find out the root username.

How can I do this for both servers?

Related questions which not helped me:

1

There are 1 best solutions below

2
On BEST ANSWER

1. FIND ROOT USERNAME

The root username is always root.

2. HOW TO CHANGE DEFAULT ROOT PASSWORD

Connect to your server using console And then:

Stop MySQL

If you are using Ubuntu or Debian:

sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL:

sudo /etc/init.d/mysqld stop

Start MySQL in safe mode

sudo mysqld_safe --skip-grant-tables &

Login (without any password)

mysql -u root

Select the database

use mysql;

Change password

update user set password=PASSWORD("YOUR NEW PASSWORD HERE") where User='root';

Flush Privileges (like refresh)

flush privileges;

Exit

quit

or

exit

Restart MySQL Ubuntu and Debian

sudo /etc/init.d/mysql stop

and

sudo /etc/init.d/mysql start

CentOS, Fedora and RHEL

sudo /etc/init.d/mysqld stop

and

sudo /etc/init.d/mysql start

Password changed successfully!

Now, you can try to login with the new password:

mysql -u root -p

(type the password when prompted)

Hope this helps!