先设置免密登录
vim /etc/my.cnf
skip-grant-tables #在[mysqld]下面添加这一行,忽略权限表
重启MySQL
/etc/init.d/mysqld restart
或
service mysql stop
service mysql start
登录
MySQL-uroot -p (提示输入密码直接按Enter)
use mysql; #进入mysql库
更新密码
alter user root@localhost identified by '新密码';
or
update mysql.user set password=PASSWORD('新密码') where User='root';
or
update mysql.user set authentication_string=password('新密码') where user='root';
FLUSH PRIVILEGES #刷新
注释skip-grant-tables 重启MySQL
vim /etc/my.cnf
skip-grant-tables