日常忘记MySQL密码,所以重置密码的方法是比必备技能。Windows和Linux系统重置密码的方式是相似的。
基本思路:
- 关闭账号验证
- 写入新密码
- 刷新账号权限
- 恢复账号检验
## 关闭权限检查(需要root权限)
mysqld_safe --skip-grant-tables &
## 更新user信息表
update mysql.user set authentication_string=password('passwd') where user='root';
## 刷新权限
flush privileges;
## 退出mysql
quit;
## 恢复权限检查(需要root权限)
mysqld_safe &