一、系统更新
1、查看系统版本:
2、Yum update
二、安装MYSQL
1、查询系统中已安装的mariadb并删除,避免与MYSQL冲突
[root@dns ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@dns ~]# rpm -e --nodeps mariadb-libs
2、添加官方的yum源并安装YUM源
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
//修改安装源etc/yum.repos.d/mysql-community.repo)
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3、安装MYSQL8.0
查看可安装版本
yum repolist enabled | grep mysql
执行安装
yum install -y mysql-community-server
4、启动MYSQL
Systemctl start mysqld.service //启动MYSQL
Systemctl enable mysqld.service //设置开机启动
systemctl daemon-reload //重新加载
systemctl status mysqld.service //查看MYSQL状态
注意:MySql安装完成之后会在LOG文件(/var/log/mysqld.log)中生成一个root的默认密码
执行grep 'temporary password' /var/log/mysqld.log
执行 mysql –uroot –p
输入ROOT密码
修改ROOT密码
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new psd';
#密码强度默认为中等,大小写字母、数字、特殊符号,只有修改成功后才能修改配置再设置更简单的密码
{扩展阅读:mysql的密码策略}
mysql>show variables like '%validate_password%';
默认的密码策略
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置:
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
或者set global validate_password.policy=0;
修改默认编码
在/etc/my.cnf配置文件的[mysqld]下添加编码配置:
重启mysql,是修改生效
#systemctl restart mysqld
远程登录用户添加
mysql> GRANT ALL PRIVILEGES ON . TO 'admin'@'%' IDENTIFIED BY '*****' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
查看用户
mysql> select host,user from mysql.user;
四、关闭SELINUX
vim /etc/selinux/config,把SELINUX改为disable即可。
五、配置防火墙,开放MYSQL端口3306
firewall-cmd --permanent --zone=public --add-port=3306/tcp //配置端口
firewall-cmd –reload //刷新防火墙