How to find MySQL root password on MySQL 5.7

CentOS/RedHat Users

If you are using Centos/Redhat MySQL rpm based installation, the root password was set at the installation time. MySQL 5.7 root password must be stored inside your MySQL error log.

Let’s take a look at your /etc/my.cnf file, to see what is the error log.

grep error -i /etc/my.cnf

You should find something like this:


Now that you know your MySQL error log path, let’s see if the MySQL 5.7 root password is there or not. Let’s grep it.

grep "temporary password" /var/log/mysqld.log

So, there is our password:

2017-05-26 [Note] A temporary password is generated for root@localhost: 34mx)qs49SNK

Debian/Ubuntu Users

Unlike on CentOS/RHEL, you will be prompted to set the root password, if you do, you already know the password. Now, if you don’t set it up when prompted, then MySQL will be created without any root password.  It is recommended to setup a root password asap.

At the logs you will see something like this:

[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

How can I get MySQL root password if I don’t have an error log?

Let’s suppose you lost your error log, it was removed by mistake or any other reason. Then you can start MySQL server using the –skip-grant-tables option, that will allow you to login to the MySQL shell and reset the root password safely.


MySQL 5.7 introduces lot of ways to improve server security, however in this case this missing root password thing has been causing lot of confusion among MYSQL server users.

However, now that you know how to find MySQL root password on MySQL 5.7, this shouldn’t be an issue anymore. Remember to take a look at the MySQL error log, that’s where the root password is.

Please follow and like us:
follow subscribe - How to find MySQL root password on MySQL 5.720


Leave a Reply

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