#修改/etc/my.cnf,新增以下行

skip-grant-tables
systemctl restart mysqld
#刷新权限
flush privileges;
#配置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssW0rd'
systemctl restart mysqld