1.修改MySQL的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行
skip-grant-tables
2、保存配置文件后,重启MySQL服务
service mysqld restart
3、再次进入MySQL命令行,输入密码时直接回车,就会进入MySQL数据库了。
mysql -uroot -p
4,改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
——————————————————————————————————————————————————————————————————
第4步报错
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option
1.先执行
flush privileges;
2.再执行
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
第4步报错
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
看一下
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
是否写成了
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';