全新安装MySQL5.7版本,会在文件 /var/log/mysqld.log中为root用户生成一个随机密码,使用下面命令查看密码:

$ grep 'temporary password' /var/log/mysqld.log
2016-02-27T07:46:08.207744Z 1 [Note] A temporary password is generated for root@localhost: kxK.lf3p9r-M

然后运行mysql_secure_installation进行设置和修改密码,也可以直接登录到mysql提示符下进行密码修改:

shell> mysql -uroot -p 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';