MySQL找回root密码的方法
方法一(通用):
1.在my.cnf或my.ini中的[mysqld]字段加入skip-grant-tables,免认证登录
2.重启mysql服务,进入CLI模式
#使用root用户
mysql -uroot
3.在mysql命令行修改root密码
use mysql;
update user set authentication_string=password('newpassword') where user='root';
flush privileges;
# mysql old version
#update user set Password=password('newpassword') where user='root';
4.去掉my.cnf或my.ini中的skip-grant-tables,重启mysqld
方法二(Debian系统):
类Debian系统可直接使用/etc/mysql/debian.cnf中[client]节提供的密码登录
#查看系统保留密码
cat /etc/mysql/debian.cnf
#使用系统用户登录
mysql -udebian-sys-maint -p