CentOS7-mysql 5.7 安装

1、配置YUM源

# 下载mysql源安装包shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

2、安装MySQL

shell> yum install mysql-community-server

3、启动MySQL服务

shell> systemctl start mysqld

查看MySQL的启动状态
shell> systemctl status mysqld

4、开机启动

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5、修改root默认密码

shell> grep 'temporary password' /var/log/mysqld.log

这个可以看到初始的密码,我们需要修改为自己想要的。

shell> mysql -uroot -p

然后输入上面的密码,连接上mysql

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

注意: mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。

修改密码策略

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略

选择0(LOW),1(MEDIUM),2(STRONG)
validate_password_policy=0

如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:

validate_password = off

重新启动mysql服务使配置生效:

systemctl restart mysqld

6、添加远程登录用户

mysql> GRANT ALL PRIVILEGES ON . TO ‘用户名’@’%’ IDENTIFIED BY ‘密码’ WITH GRANT OPTION;

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

Leave a Reply