shell> sudo grep 'temporary password' /var/log/mysqld.log
// 大概会获得这样一个输出 joIiu=pRy4FO 就是密码
2020-08-07T06:43:58.772150Z 1 [Note] A temporary password is generated for root@localhost: joIiu=pRy4FO
用刚才的密码登录
shell> mysql -uroot -p
// 注: 登陆成功后 会切换到 mysql 命令行
修改默认密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
// sql命令行 需要 ; 做结束符
// 修改密码规则 mysql 存在默认密码规则
// 更改密码长度
set global validate_password_length=0;
// 更改密码策略为LOW
set global validate_password_policy=0;
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
update user set host = '%' where user = 'root';
// 允许root 用户在任何地方远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
// 修改立即生效
flush privileges;
// 若是报错Access denied for user 'root'@'%' to database 'test'.
update mysql.user set Grant_priv='Y',Super_priv='Y' where user = 'test' and host = '%';
// 修改完成重启数据库