有旧密码
无旧密码
在关闭状态:
systemctl stop mysql
保证有mysqld
mkdir /var/run/mysqld chown mysql /var/run/mysqld
开启无需密码模式
mysqld_safe --skip-grant-tables&
进入
mysql -u root -p
清空旧密码
UPDATE mysql.user SET authentication_string=null WHERE User='root'; flush privileges;
更改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; flush privileges;
重启mysql
systemctl start mysql