-1

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:

halfer
  • 19,824
  • 17
  • 99
  • 186
MM PP
  • 4,050
  • 9
  • 35
  • 61

1 Answers1

4

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!