What is the default root pasword for MySQL 5.7

前端 未结 13 1158
梦谈多话
梦谈多话 2020-12-22 16:55

Cannot login to MySQL database after fresh install with root ID and empty/no password like other older MySQL versions do

相关标签:
13条回答
  • 2020-12-22 17:45

    None of these answers worked for me on Ubuntu Server 18.04.1 and MySQL 5.7.23. I spent a bunch of time trying and failing at setting the password and auth plugin manually, finding the password in logs (it's not there), etc.

    The solution is actually super easy:

    sudo mysql_secure_installation
    

    It's really important to do this with sudo. If you try without elevation, you'll be asked for the root password, which you obviously don't have.

    0 讨论(0)
  • 2020-12-22 17:47

    MySQL 5.7 or newer generates a default temporary password after fresh install.

    To use MySQL first you would be required to get that password from the log file which is present at the /var/log/mysqld.log. So follow the following process:

    1. grep 'temporary password' /var/log/mysqld.log

    2. mysql_secure_installation

    The second command is required to change the password for MySQL and also to make certain other changes like removing temporary databases, allow or disallow remote access to root user, delete anonymous users etc…

    0 讨论(0)
  • 2020-12-22 17:50

    After you installed MySQL-community-server 5.7 from fresh on linux, you will need to find the temporary password from /var/log/mysqld.log to login as root.

    1. grep 'temporary password' /var/log/mysqld.log
    2. Run mysql_secure_installation to change new password

    ref: http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

    0 讨论(0)
  • 2020-12-22 17:52

    I just installed Linux Mint 19 (based on Ubuntu 18.04) on my machine. I installed MySQL 5.7 from the repo (sudo apt install mysql-server) and surprisingly during installation, the setup didn't prompt to enter root password. As a result I wasn't able to login into MySQL. I googled here and there and tried various answers I found on the net, including the accepted answer above. I uninstalled (purging all dpkgs with mysql in its name) and reinstalled again from the default Linux Mint repositories. NONE works.

    After hours of unproductive works, I decided to reinstall MySQL from the official page. I opened MySQL download page (https://dev.mysql.com/downloads/repo/apt) for apt repo and clicked Download button at the bottom right.

    Next, run it with dpkg:

    sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
    

    At the installation setup, choose the MySQL version that you'd like to install. The default option is 8.0 but I changed it to 5.7. Click OK to quit. After this, you have a new MySQL repo in your Software Sources.

    Update your repo:

    sudo apt update
    

    Finally, install MySQL:

    sudo apt install mysql-server
    

    And now I was prompted to provide root password! Hope it helps for others with this same experience.

    0 讨论(0)
  • 2020-12-22 17:53

    In my case the data directory was automatically initialized with the --initialize-insecure option. So /var/log/mysql/error.log does not contain a temporary password but:

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

    What worked was:

    shell> mysql -u root --skip-password
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    

    Details: MySQL 5.7 Reference Manual > 2.10.4 Securing the Initial MySQL Account

    0 讨论(0)
  • 2020-12-22 17:58

    MySQL server 5.7 was already installed by default on my new Linux Mint 19.

    But, what's the MySQL root password? It turns out that:

    The default installation uses auth_socket for authentication, in lieu of passwords!

    It allows a password-free login, provided that one is logged into the Linux system with the same user name. To login as the MySQL root user, one can use sudo:

    sudo mysql --user=root
    

    But how to then change the root password? To illustrate what's going on, I created a new user "me", with full privileges, with:

    mysql> CREATE USER 'me'@'localhost' IDENTIFIED BY 'my_new_password';
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'me'@'localhost' WITH GRANT OPTION;
    mysql> FLUSH PRIVILEGES;
    

    Comparing "me" with "root":

    mysql> SELECT user, plugin, HEX(authentication_string)  FROM mysql.user WHERE user = 'me' or user = 'root';
    +------+-----------------------+----------------------------------------------------------------------------+
    | user | plugin                | HEX(authentication_string)                                                 |
    +------+-----------------------+----------------------------------------------------------------------------+
    | root | auth_socket           |                                                                            |
    | me   | mysql_native_password | 2A393846353030304545453239394634323734333139354241344642413245373537313... |
    +------+-----------------------+----------------------------------------------------------------------------+
    

    Because it's using auth_socket, the root password cannot be changed: the SET PASSWORD command fails, and mysql_secure_installation desn't attain anything...

    ==> To zap this alternate authentication mode and return the MySQL root user to using passwords:

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SOME_NEW_ROOT_PASSWORD';
    

    A good explanation.

    More details from the MySQL manual.

    0 讨论(0)
提交回复
热议问题