MySQL 5.7 密碼重設
最近安裝了 MySQL 5.7的版本後發現
使用預設的Root密碼(空白)居然無法進入
上網查了一下, 居然log檔裡有很特別的密碼字串
grep 'temporary password' /var/log/mysqld.log
還好用以下的方式,將初始密碼給改掉了!!
1. Stop mysql:
systemctl stop mysqld
- Set the mySQL environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" -
Start mysql usig the options you just set
systemctl start mysqld -
Login as root
mysql -u root -
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 -
Stop mysql
systemctl stop mysqld -
Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS -
Start mysql normally:
systemctl start mysqld
Try to login using your new password:
7. mysql -u root -p
近期迴響