安装环境
- 系统是centos 7的64版本
- mysql的版本是MySQL-5.6.44-1.el7
安装过程
- 解压
在/usr/local/src下创建mysql目录并将安装文件
MySQL-5.6.44-1.el7.x86_64.rpm-bundle.tar
拷贝到此目录下。并利用以下命令解压
tar -xvf MySQL-5.6.44-1.el7.x86_64.rpm-bundle.tar
得到以下文件
![](https://img.haomeiwen.com/i2196908/b0f01f4a860741bb.png)
- 安装
利用如下命令安装以下两文件
rpm -ivh MySQL-server-5.6.44-1.el7.x86_64.rpm
rpm -ivh MySQL-client-5.6.44-1.el7.x86_64.rpm
ps:安装过程中,如果centos上之前有安装其他数据库的话,可能会提示产生冲突导致安装失败,笔者在系统预装了MariaDB所以导致开始的时候安装失败,此时可以先卸载已有的数据库(当然是在你不需要改数据库的前提下)再尝试安装。
- 实现远程连接
实现远程连接需要做好以下几个步骤
- 利用以下命令为root开放远程连接权限。
grant all privileges on . to root@'%' identified by "password";
flush privileges;
- centos7默认使用firewall作为防火墙,所以要先改为iptables防火墙。(至于为什么关掉firewall暂时还不明白)
systemctl stop firewalld #先关闭firewall
systemctl mask firewalld #直接暴力禁止掉firewall
yum install iptables-services #安装iptables
- 在/etc/sysconfig/iptables写入
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
保存规则
service iptables save
- 重启防火墙
service iptables restart
或
systemctl start iptables.service
- 查看端口
iptables -L -n
![](https://img.haomeiwen.com/i2196908/b3693c236865de5e.png)
- 系统启动时自动启动mysql服务
chkconfig --add mysql #加入到系统服务
chkconfig mysql on #自动启动
chkconfig #查询列表
最后你就可以实现数据库的远程连接。
参考:https://blog.csdn.net/qq_37960007/article/details/80374782
网友评论