1.下载安装包
下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
上传到 /home 目录下
2.解压安装包
tar -xf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar -C /home/mysql/
3.查询并卸载系统自带的Mariadb
rpm -qa | grep mariadb
rpm -e --nodeps 文件名
4.查询并卸载系统老旧版本的Mysql
rpm -qa | grep mysql
rpm -e --nodeps 文件名
5.安装libaio环境(已经存在不需要)
yum install libaio
6.执行Rpm包安装(按顺序)
rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm
如果报如下错误:
可通过http://www.rpmfind.net/linux/rpm2html/search.php?query=net-tools(x86-64)下载对应版本的安装包,上传至Linux系统,通过命令:yum localinstall -y net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
进行安装。
7.启动mysql服务
查看mysql服务是否启动
service mysqld status
启动服务:
systemctl start mysqld
8.重置root密码
查看随机生成的密码
grep ‘temporary password’ /var/log/mysqld.log
9.修改root用户密码
mysql -u root -p
mysql> Enter password: (输入刚才查询到的随机密码)
mysql> SET PASSWORD FOR ‘root’@‘localhost’= “Jstw@123”;
9.开放外部网段访问3306端口
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘Jstw@123’ WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql> exit
10.这里设置开机自启动
方法一 、vi /etc/rc.local 添加service mysqld start
方法二 、 执行 systemctl enable mysqld.service
(# 注意systemctl 中规定、服务的配置文件要以.service 为后缀
11.开启防火墙mysql 3306端口的外部访问
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
12.查看已开启的端口
firewall-cmd --list-all
netstat -ntpl (TCP类型已开放的端口)