I have installed mysql 5.7 on a Red Hat Enterprise Linux 5.5 server and when I tried to run following command after installation it is asking for a password for root@localhost.


I have never set a root password and I'm logged in to Linux as root user.

Then I have found following documentation for resetting root password and followed that one too.


But even after starting the server with following command it is asking for a password

/etc/init.d/mysqld start --skip-grant-tables &

I have tried starting the server with init-file option, but no success.

Does anyone know how to reset the password correctly or default MySQL password?

migrated from stackoverflow.com Dec 22 '17 at 16:55

This question came from our site for professional and enthusiast programmers.


Restart the service without authentication


service mysql stop
service mysql start --skip-grant-tables --skip-networking

Other sysv

If you're on a sysv Linux use this

/etc/init.d/mysqld stop
/etc/init.d/mysqld start --skip-grant-tables --skip-networking &


Then you need to login as root

mysql -u root -p

Then when logged in run

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Difference between other guides

There are a lot of "guides" on this, for clarity,

  • Some guides use the older SET PASSWORD syntax, that's pre 5-7.6, don't use that anymore.
  • Some guides just don't use --skip-networking, that's unsafe.
  • Some guides don't connect with the -u root that's more error-prone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.