Where is the MySQL 5.7 root password? That was the question I made yesterday when I was going to connect to MySQL 5.7 console. Here is what I found about this simple question for MySQL 5.7 users.
Find MySQL 5.7 root password
Unlike previous versions, by default MySQL 5.7 automatically creates a temporary root password. And if you come from previous MySQL versions you should know that on the old versions you were the one that was in charge of configuring the mysql root password.
MySQL 5.7 creates the root password for you, and it’s something that lot of users are complaining about.
How can I get my MySQL 5.7 root password? Where can I find it?
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
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.