场景:1.忘记了mysql给你的初始密码,2.怎么输入初始密码都上不去。
那么你可以使用如下方法重置密码:
我的mysql版本为:Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64) using EditLine wrapper
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>