附录:MySQL忘记root密码

中小型规模网站集群架构:MySQL忘记root密码

: Ago linux运维群:https://hankbook.cn


前言

你忘记系统root密码的时候,你怎么解决的?
不就是single用户进行修改密码吗?这里原理是类似的。

步骤

单一实例的找回密码

1.停掉mysql服务

[shell]: /etc/init.d/mysqld stop

2.使用--skip-grant-tables启动mysql,忽略授权登录
[shell]表示在shell下执行命令
[mysql]表示在mysql里面执行命令

[shell]:mysqld_safe --skip-grant-tables --user=mysql &
[shell]:mysql

3.用修改密码2来修改密码

[mysql]:update mysql.user set password=password("aige") where user='root' and host='localhost'

4.重启mysql服务

[shell]:mysqladmin -uroot -paige shutdown

多实例找回密码

1.关闭mysql服务

[shell]:killall mysql

2.启动时加--skip-grant-tables参数 忽略授权表

[shell]:mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables &
[shell]:mysql -u root -p -S /data/3306/mysql.sock

3.修改密码方法

[mysql]:update mysql.user set password=password("aige") where user='root' and host='localhost' 

4.重启用新密码登录

posted @ 2017-04-05 11:35  汉克书  阅读(304)  评论(0编辑  收藏  举报