1.安装mysql的yum仓库
执行以下命令:
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2.安装mysql
dnf install mysql-community-server
3.开启mysql服务
service mysql start
4.查找默认密码
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。 只有启动过一次mysql才可以查看临时密码,输入以下命令查看密码:
grep 'temporary password' /var/log/mysqld.log
输出如下:
[root@VM_0_13_centos init.d]# grep 'temporary password' /var/log/mysqld.log
2018-03-09T13:03:32.859149Z 1 [Note] A temporary password is generated for root@localhost: IVXhn:4E3uQ4
5.登陆mysql并且修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
修改密码,会出现:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
必须修改两个全局参数: 首先,修改validate_password_policy参数的值
set global validate_password_policy=0;
再修改密码的长度
set global validate_password_length=1;
再次执行修改密码就可以了
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
6.授权其他机器连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'passwort' WITH GRANT OPTION; //passwort改为mysql登陆密码
FLUSH PRIVILEGES;