在centos7上实现mysql远程连接

2019-05-17  本文已影响0人  衣忌破

安装环境

安装过程

tar -xvf MySQL-5.6.44-1.el7.x86_64.rpm-bundle.tar

得到以下文件


mysql0.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所以导致开始的时候安装失败,此时可以先卸载已有的数据库(当然是在你不需要改数据库的前提下)再尝试安装。

实现远程连接需要做好以下几个步骤

  1. 利用以下命令为root开放远程连接权限。

grant all privileges on . to root@'%' identified by "password";
flush privileges;

  1. centos7默认使用firewall作为防火墙,所以要先改为iptables防火墙。(至于为什么关掉firewall暂时还不明白)

systemctl stop firewalld #先关闭firewall
systemctl mask firewalld #直接暴力禁止掉firewall
yum install iptables-services #安装iptables

  1. 在/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

  1. 重启防火墙

service iptables restart

systemctl start iptables.service

  1. 查看端口

iptables -L -n

mysql2.png

chkconfig --add mysql #加入到系统服务
chkconfig mysql on #自动启动
chkconfig #查询列表

最后你就可以实现数据库的远程连接。
参考:https://blog.csdn.net/qq_37960007/article/details/80374782

上一篇下一篇

猜你喜欢

热点阅读