1,关闭mysql服务
/etc/init.d/mysql stop
关闭服务后需要再进行一步杀死mysql进程
2,查找mysql还在运行的进程
ps -A|grep mysql
3,根据进程id杀死进程(这一点很重要,不杀死所有mysql进程无法启动安全模式)
kill -9 进程id
4,进入安全模式
/usr/bin/mysqld_safe --skip-grant-tables --skip-networking &
执行这句后可以无密码登录mysql
5,无密码登录mysql
mysql -u root
6,重置root密码
update user set password=PASSWORD("new_pass") where user='root' and Host = 'localhost';
7,刷新权限
flush privileges;
8,退出mysql
exit;
9,重启mysql服务
/etc/init.d/mysql restart