重置root用户密码
第一步:跳过MySQL的密码认证过程,配置my.cnf文件
[root@ora01 ~]\# whereis my #查找自己服务器my.cnf文件位置
[root@ora01 ~]\# vim /etc/my.cnf #编辑my.cnf文件
vim> :/ mysqld #在编辑模式查询[mysqld]的位置
在[mysqld]后面任意一行添加 skip-grant-tables
然后保存文档并退出。
第二步:重启服务,设置密码
-
重启MySQL服务:
[root@ora01 ~]\# systemctl restart mysqld.service
重启可能报错找不到pid文件。可以再指定路径下重新生成一个。或者重新指定目录配置。
[root@ora01 《》报错路径》]\# ps -ef|grep mysqld|awk '{print $2}'|sed 1d |sed 2d > ${HOSTNAME}.pid
-
进入mysql,重置密码:
[root@ora01 ~]\# mysql #进入msyql
mysql> update mysql.user set authentication_string=password("你的新密码") where user="root"; --5.7+版本使用。 mysql> update mysql.user set password=password("你的新密码") where user="root"; --5.7-版本使用。 mysql> flush privileges; mysql> quit
第三步,大功告成!
-
编辑my.cnf,
[root@ora01 ~]\# vim /etc/my.cnf #编辑my.cnf文件
删除
skip-grant-tables
配置 -
重启服务,至此修改密码完毕。
[root@ora01 ~]\# systemctl restart mysqld.service