mysql-忘记root密码

1、开一个终端关闭mysql:brew services stop mysql(本人mac brew 命令安装的mysql)

2、执行 mysqld --skip-grant-tables 命令(–skip-grant-tables 的意思是启动 MySQL 服务的时候跳过权限表认证),如果报错unknown option --skip-grant-table 就执行mysqld -nt --skip-grant-tables

3、开第二个终端执行 mysql -uroot -p 提示输入密码,直接回车(不用输入密码)

4、选择数据库:use mysql;

5、更新root的密码:update user set authentication_string=password('新密码') where user='root' and Host='localhost';

6、刷新权限:flush privileges;

7、退出:quit

8、重新登录:mysql -uroot -p 提示输入密码,这时输入密码才能登录。

发布了3 篇原创文章 · 获赞 4 · 访问量 130

猜你喜欢

转载自blog.csdn.net/daofengsuoxiang/article/details/104534925
今日推荐