一、系统更新
1、查询系统版本
[root@HostName ~]# uname -a
Linux HostName 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@HostName ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
2、系统更新
yum update
二、安装MYSQL
1、 查询系统中已安装的mariadb并删除,避免与MYSQL冲突
[root@HostName ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@HostName ~]# rpm -e --nodeps mariadb-libs
2、添加官方的yum源并安装YUM源(用5.7源修改为8.0源)
[root@HostName ~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
[root@HostName ~]#yum localinstall mysql57-community-release-el7-8.noarch.rpm
[root@HostName ~]#vi etc/yum.repos.d/mysql-community.repo
将MYSQL57复制一份,并修改为8.0的,注意:需要禁用5.7的源
[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并修改ROOT密码
注意:MySql安装完成之后会在LOG文件(/var/log/mysqld.log)中生成一个root的默认密码
[root@HostName ~]#grep 'temporary password' /var/log/mysqld.log
2018-10-10T00:54:47.464966Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dogl;VhEq8HH
[root@HostName ~]# mysql –uroot –p
Enter password:
输入ROOT密码
修改ROOT密码
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new psd';
#密码强度默认为中等,大小写字母、数字、特殊符号,只有修改成功后才能修改配置再设置更简单的密码
四、关闭SELinux
[root@HostName ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
使配置即时生效
[root@HostName ~]#setenforce 0
五、 配置防火墙,开放MYSQL端口3306
[root@HostName ~]#firewall-cmd --permanent --zone=public --add-port=3306/tcp //配置端口
[root@HostName ~]#firewall-cmd –reload //刷新防火墙
{扩展阅读:mysql的密码策略}
mysql>show variables like '%validate_password%';
+---------------------------------------+--------+
| Variable_name | Value |
+---------------------------------------+--------+
| validate_password_check_user_name | ON |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+---------------------------------------+--------+
7 rows in set (0.01 sec)
默认的密码策略
1. validate_password_policy:密码策略,默认为MEDIUM策略
2. validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
3. validate_password_length:密码最少长度
4. validate_password_mixed_case_count:大小写字符长度,至少1个
5. validate_password_number_count :数字至少1个
6. validate_password_special_char_count:特殊字符至少1个
修改密码策略
在/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]下添加编码配置:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重启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;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)