MySQL 5.7 auto-generated root password

Hi There.

You may have noticed something different when you install a fresh copy of MySQL 5.7 or 8.0 either via yum or using binary source. The root password is auto-generated by default, unlikely on older versions where it was empty.
Ok, and where can I find it?

Centos
cat /var/log/mysqld.log | grep "A temporary password is generated for" | awk '{print $NF}'
Example:

[root@master ~]# cat /var/log/mysqld.log | grep "A temporary password is generated for" | awk '{print $NF}'
a3BGf#TY.pBj

Binary distribution
Once you initialization the datadir mysqld --initialize you will see the bellow log printed on screen:

. . .
2016-01-13T21:05:03.070322Z 1 [Note] A temporary password is generated for root@localhost: vL8n>Hs%kr>s
. . .

You will be required to change the password on the first login. You can do it following step 2 of this article.

That’s it.
Now you guys know how to find the auto generated root password for MySQL 5.7.

See you next time.

13 thoughts on “MySQL 5.7 auto-generated root password

      1. Marcelo, thanks for this post. I have been having this problems for several days and I would appreciate it if you could help me out

        I downloaded MySQL and didn’t jot down the temporary password that pops on the screen. Since then, I have not been able to reset my root password. No matter where I search, I can’t find a solution. Any help?

      2. So I am typing in the terminal.
        /etc/init.d/mysql stop
        this popped up -bash: /etc/init.d/mysql: No such file or directory
        what should I do??
        Thanks so much for offering this prompt help! Quickest response I got on line so far! Thanks for helping me fix this issue.

        I stopped server thru system preference manually and tried next step

        mysqld_safe-skip-grant-tables

        that also gave this

        -bash: mysqld_safe-skip-grant-tables: command not found

        Sorry I am newbie. Hopefully we fix this so I continue to learn

      3. As you already stopped the service, go to /etc/my.cnf and add skip-grant-tables right after [mysql] (line below)

        then start the service again, login with any user, and change the password like in the article I sent on my above comment. Then remove the skip-grant-tables from my.cnf and restart the service .
        Try to login with your new pwd.

      4. Marcelo, i am so sorry I don’t understand what “go to /etc/my.cnf and add skip-grant-tables right after [mysql] (line below)” refers to

        I have only terminal and server to stop or run. do i need to have other files?

        Can you type in step by step so i can copy and paste the code to see how it works and learn from there if i need type in your instruction in the terminal? Because I translated your first instruction into this and it doesn’t seem right
        /etc/my.cnf-skip-grant-tables
        gave this -bash: /etc/my.cnf-skip-grant-tables: No such file or directory

      5. Hi Emin,
        I mean open the file on the file editor (vim / nano / gedit), add a new line and type skip-grant-tables. Save the file and restart mysql service

      6. I have terminal, sublime text and mysql-5.7.13-osx10.11-x86_64.pkg. There are no files that I can go to. when I go to (mysql-5.7.13-osx10.11-x86_64.pkg) there is no files but it goes to installation again.

        Thanks for patiently helping me figure this out.

      7. Hey Marcelo,

        I was wondering if you could help me out with the following issue. thanks!

        I have terminal, sublime text and mysql-5.7.13-osx10.11-x86_64.pkg. There are no files that I can go to. when I go to (mysql-5.7.13-osx10.11-x86_64.pkg) there is no files but it goes to installation again.

        a) I have this installed

        https://dev.mysql.com/doc/refm

        b) Do I need to install MySQL Launch Daemon as well?

        https://dev.mysql.com/doc/refm

        c) And the MySQL Preference Pane?

        or all of this(b and c) is already installed when installed what(a) I have now?

        Sorry i am very confused with all this.

        Thanks for patiently helping me figure this out.

  1. That’s great! Thanks,
    Do you know how to prevent MySql from generating a random password and instead use the once chosen by the user when running mysqld –initialize ? I want to force using a password on a no install version distributed with a standalone application ­čÖé

Leave a Reply

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