本文共 916 字,大约阅读时间需要 3 分钟。
MySql的远程访问和远程端口开放方法
ljj17173 • 2018 年 09 月 28 日
在远程服务器上,数据库有时候是需要进行远程访问的,但默认Mysql没开启授权远程访问,相关的端口在服务器上可能也没有开放,所以,要进行远程访问就要解决这些问题
一、开启Mysql的远程访问授权
我建议是用的直接授权法(对于root账户)
1.登陆Mysql[root@localhost software]> mysql -u root -proot
2.输入相关指令mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
[FLUSH PRIVILEGES]是刷新用户权限信息的指令
二、开启服务器的3306端口(我这是CentOS系统的示例)
CentOS默认使用了firewall作为防火墙,为了方便,我们改成iptables防火墙
1、关闭firewall:systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
2、安装iptables防火墙yum install iptables-services -y
3.启动设置防火墙> systemctl enable iptables
> systemctl start iptables
4.查看防火墙状态systemctl status iptables
5.开放443端口(HTTPS)iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
6.保存上述规则service iptables save
7.重启,和开机启动systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
转载地址:https://blog.csdn.net/weixin_32823555/article/details/113137731 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!