Centos7 安装 MySQL5.7
Centos安装MySQL
官网yum repository 下载安装包
wget http://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
安装下载下来的rpm包
yum localinstall mysql80-community-release-el6-3.noarch.rpm
查看可用的安装包
yum repolist enabled|grep mysql

更改mysql版本
vim /etc/yum.repos.d/mysql-community.repo

MySQL8.0 的 enable = 0,MySQL5.7 的 enable = 1
安装mysql
yum install mysql-community-server -y
启动mysql并更改相关配置
- 启动mysql
service mysqld start
- 查看mysql是否自启动,并且设置开启自启动
chkconfig --list | grep mysqld
chkconfig mysqld on
- 查看初始密码
grep "password" /var/log/mysqld.log

- 修改密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
修改的密码过于简单可能会报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
执行以下语句:
set global validate_password_policy=0;
set global validate_password_length=4;
再执行修改密码语句
- 开放root账户远程访问
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
- 刷新权限表
FLUSH PRIVILEGES;
打开3306端口远程访问
将centos7自带的firewall防火墙更换为iptables防火墙
1、关闭firewall防火墙
[root@centos7 html]# systemctl stop firewalld #停止firewall防火墙
[root@centos7 html]# systemctl disable firewalld #禁止firewall开机启动
[root@centos7 html]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2、安装iptables防火墙并设置自启动
安装
[root@centos7 html]# yum install -y iptables iptables-services
自启动设置
[root@centos7 html]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@centos7 html]# systemctl status iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Fri 2017-08-18 23:41:19 CST; 2min 22s ago
Main PID: 3603 (code=exited, status=0/SUCCESS)
3、查看iptables配置文件,添加3306端口
打开iptables文件
vi /etc/sysconfig/iptables
进入编辑页面,在指定位置新增以下配置。放在 -A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT 后面
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
修改完保存退出,重启网卡服务
service iptables restart
查看端口开放信息
service iptables status
CentOS7安装MySQL报错Failed to start mysqld.service: Unit not found解决办法

浙公网安备 33010602011771号