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 either via yum or using binary source. The root password is auto-generated.
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.

Liked? Help and Share!
This entry was posted in install, MySQL, password, Security. Bookmark the permalink.
  • Hi,
    I would like to add since MySQL 5.7.11, the default value of the default_password_lifetime system variable that controls the global password expiration policy has been changed from 360 (360 days) to 0 (no password expiration).
    https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-11.html
    That probably would avoid the “1 yr later big panic” ­čśë

    • Marcelo Altmann

      Thanks for the valuable comment!

      • Emin

        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?

        • Marcelo Altmann
          • Emin

            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

          • Marcelo Altmann

            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.

          • Emin

            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

          • Marcelo Altmann

            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

          • Emin

            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.

          • Emin

            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.

          • Emin

            Marcelo, any help above comments? Thanks!