mac忘记mysql密码解决方案

mysql-5.7.28

默认安装路径 /usr/local/mysql

1. 关闭mysql进程

sudo /usr/local/mysql/support-files/mysql.server stop

2. 使用--skip-grant-tables方式启动mysql

sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables --user=root

3. 无密码方式连接mysql

/usr/local/mysql/bin -uroot

4. 更新root密码

  5.7版本及以上:

mysql>update mysql.user set authentication_string=password('新密码') where user='root' and Host='localhost';

  5.7以下版本:

mysql>update mysql.user set password=password('新密码') where user='root' and host='localhost';

5. 刷新权限表,使密码修改生效

mysql>flush privileges;

6. 重启mysql

sudo /usr/local/mysql/support-files/mysql.server restart

7. 带密码方式登陆

/usr/local/mysql/bin -uroot -p,//交互输入已经修改的密码

8. 采用此种方式修改密码后,再次登陆系统会强制修改密码

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

9. 修改密码

set password for 'root'@'localhost' = password('新密码');

 

你可能感兴趣的:(mysql)