1.编辑my.cnf文件加入skip-grant-tables,忽略密码登录
[[email protected] ~]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
[[email protected] ~]# sudo service mysql restart
2.修改密码
[[email protected] ~]# mysql
mysql> update mysql.user set authentication_string=PASSWORD(‘root1234′) where user=’root’ and host=’localhost’;
mysql> flush privileges;
mysql> exit;
3.开启密码登录
[[email protected] ~]# vi /etc/my.cnf
[mysqld]
#skip-grant-tables
[[email protected] ~]# sudo service mysql restart
4.修复错误
[[email protected] ~]# mysql -uroot -proot1234;
[[email protected] ~]# mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘root1234’
Query OK, 0 rows affected (0.09 sec)