忘记MySQL密码,如何破?

1.单实例情况

现将数据库停掉

/etc/init.d/mysqld stop

使用如下命令启动数据库

mysqld_safe --skip-grant-tables --user=mysql &

现在可以使用mysql命令登陆了

mysql -uroot

然后就可以改密码了

update mysql.user set password=password("password") where user=‘root‘ and host=‘localhost‘;


2.多实例情况

先将数据库停掉,然后使用如下命令启动数据库

/bin/sh /app/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables --user=mysql &

登陆

mysql -uroot -S mysql.sock

然后就可以改密码了

mysql>update mysql.user set password=password("password") where user=‘root‘ and host=‘localhost‘;

mysql>flush privileges;

本文出自 “老暖男的博客” 博客,请务必保留此出处http://ashine.blog.51cto.com/1632639/1654067

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。