MySQL 5.7 密碼重設

最近安裝了 MySQL 5.7的版本後發現
使用預設的Root密碼(空白)居然無法進入
上網查了一下, 居然log檔裡有很特別的密碼字串
grep 'temporary password' /var/log/mysqld.log

還好用以下的方式,將初始密碼給改掉了!!
1. Stop mysql:
systemctl stop mysqld

  1. Set the mySQL environment option
    systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

  2. Start mysql usig the options you just set
    systemctl start mysqld

  3. Login as root
    mysql -u root

  4. Update the root user password with these mysql commands
    mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> quit

  5. Stop mysql
    systemctl stop mysqld

  6. Unset the mySQL envitroment option so it starts normally next time
    systemctl unset-environment MYSQLD_OPTS

  7. Start mysql normally:
    systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p

您可能也會喜歡…

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *