Home > Database > Mysql Tutorial > body text

Red Hat 下 MySQL root密码恢复

WBOY
Release: 2016-06-07 17:23:54
Original
825 people have browsed it

今儿碰到一个案例,MySQL的root密码丢失,要恢复,说下环境先:Red Hat Enterprise Linux 6.3 x86_64,MySQL 5.5.28,按照自己以

今儿碰到一个案例,MySQL的root密码丢失,要恢复,,说下环境先:

Red Hat Enterprise Linux 6.3 x86_64

MySQL  5.5.28

按照自己以往经验是修改my.cnf,在[mysqld]添加skip-grant-tables,然后重启MySQL,就可以试用mysql免密码登陆,然后就可以修改密码了,但是这招好像是不怎么灵了,有另一套可行的简单的办法!

1.首先正常停止MySQL

service mysql stop

2.新建文件test.init

UPDATE mysql.user SET Password=PASSWORD('') WHERE User='root';

FLUSH PRIVILEGES;

3.启动

mysqld_safe --init-file=test.init &

这样就可以使用mysql免密码登陆MySQL了。实际上,在test.init中就已经重新设置了密码,只是将密码设置为空了,在第2部PASSWORD括号里可以填上你的密码。

4.正常启动

执行了第3步后,如果再执行service mysql restart,会发现MySQL报错起不来,但是3306仍是监听状态,因为第3步中已经用mysql_safe进行了特殊了启动,我们要kill掉这个进程:

ps aux | grep mysql

kill -9 PID

找到MySQL的进程,Kill掉,然后执行service命令正常启动即可。

linux

Related labels:
r
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!