msyql8.0修改密码

  1. 修改配置文件:添加 skip-grant-tables
cd /etc/mysql/mysql.conf.d/
sudo vim mysqld.cnf
  1. 重启mysql服务。
sudo service mysql restart
  1. 登录mysql, 此时不需要密码
mysql -u root -p
  1. 进入mysql数据库
use mysql
  1. 将authentication_string 置空
update user set authentication_string='' where user='root';
  1. 设置新密码
alter user 'root'@'localhost' identified by 'newpassword'
  1. 异常 ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 处理
FLUSH PRIVILEGES;
  1. 设置新密码
alter user 'root'@'localhost' identified by 'newpassword';
  1. 异常 ERROR 1524 (HY000): Plugin ‘auth_socket’ is not loaded
# 查看plugin
select user,plugin from mysql.user
# 设置为5.x版本密码认证方式
update user set plugin=‘mysql_native_password’ where user=‘root’;
FLUSH PRIVILEGES;

10 . 设置新密码

alter user 'root'@'localhost' identified by 'newpassword';
FLUSH PRIVILEGES;
  1. 将第一步的skip-grant-tables注释掉;

  2. 重启mysql服务