# 进入系统根目录
cd
# 下载mysql5.7
sudo wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
# 清除yum缓存
sudo yum clean all
# 建立缓存
sudo yum makecache
# 安装
sudo yum install mysql-server
# 启动
sudo /bin/systemctl start mysqld.service
# 查询密码
sudo grep 'temporary password' /var/log/mysqld.log
# 返回密码 “,u5gwe0jpc%E”
2019-07-12T07:43:16.323336Z 1 [Note] A temporary password is generated for root@localhost: ,u5gwe0jpc%E
# 进入mysql
mysql -u root -p
# 输入密码:
,u5gwe0jpc%E
# 修改密码,需要包含大小写字母、数字和特殊字符
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abc_00000000';
# 退出mysql
exit
# MySQL安装完成后,进行相关配置
# 安装成功后,将其加入开机启动
sudo systemctl enable mysqld
# 启动mysql服务进程
sudo systemctl start mysqld
# 配置mysql(设置密码等)
sudo mysql_secure_installation
Set root password? [Y/n] y [设置root用户密码]
Remove anonymous users? [Y/n] y [删除匿名用户]
Disallow root login remotely? [Y/n] y [禁止root远程登录]
Remove test database and access to it? [Y/n] y [删除test数据库]
Reload privilege tables now? [Y/n] y [刷新权限]
# 开放3306端口,使其它客户机也可以访问MySQL服务
# CentOS7默认使用的是firewall作为防火墙,我这里改为习惯常用的iptables防火墙
# 关闭防火墙
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
sudo systemctl mask firewalld.service
# 安装iptables防火墙
sudo yum install -y iptables-services
# 启动设置防火墙
sudo systemctl enable iptables
sudo systemctl start iptables
# 查看防火墙状态
sudo systemctl status iptables
# 增加3306端口
sudo vim /etc/sysconfig/iptables
# 增加: 按键 “i”插入
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
# 按Esc,输入“:qw”,即可保存退出
# 重启防火墙使配置生效
sudo systemctl restart iptables.service