解决忘记mysql密码的问题(linux)

1:打开/etc/my.cnf
2:找到mysqld
3:添加skip_grant_tables在mysqld下面,然后退出保存wq
4:重启service mysql restart
5:mysql -u user -p 回车 直接进去
6:然后执行命令 update mysql.user set password=password(‘root’) where user=‘root’;如果提示ERROR 1054 (42S22): Unknown column ‘password’ in 'field list’的错误,是因为MYSQL版本过高,然后执行update mysql.user set authentication_string=password(‘root’) where user=‘root’
7:flush privileges;
8:exit;
9:去掉my.cnf的skip_grant_tables
10:重启service mysql restart
11:完事

名词解释
skip_grant_tables:不启动grant-tables授权表
flush privileges:新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问)

本文参考:http://blog.sina.com.cn/s/blog_cca6ddf80102w61m.html

猜你喜欢

转载自blog.csdn.net/onlymayao/article/details/83380227