预览模式: 普通 | 列表

CentOS6开启MySQL远程访问

1.开放MySQL访问端口3306

 
修改防火墙配置文件
 
vi /etc/sysconfig/iptables 
 
加入端口配置     
 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
 
重新加载规则
 
service iptables restart  
 
 
 
2.修改mysql库里的host
 
登录mysql;
 
use mysql
 
update user set host='%' where user='root' and host='localhost';
 
记得一定还得修改密码,因为这时密码已失效,虽然本地还可以原密码登录,可远程改了host后还是没法访问
 
Update user SET password=password("root") Where user='root'; 
 
flush privileges;
 
3.重启mysql,远程就可以访问了
 
service mysqld restart;
 
 
 
 CentOS7开启MySQL远程访问
CentOS7这个版本的防火墙默认使用的是firewall,与之前的版本使用iptables不一样。按如下方便配置防火墙:
 
1、关闭防火墙:sudo systemctl stop firewalld.service
 
 
2、关闭开机启动:sudo systemctl disable firewalld.service
 
 
 
3、安装iptables防火墙
 
执行以下命令安装iptables防火墙:sudo yum install iptables-services
 
4、配置iptables防火墙,打开指定端口(CentOS6一样)
 
5、设置iptables防火墙开机启动:sudo systemctl enable iptables
 
6、之后的和CentOS6一样

Tags: centos

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 109

 广告位

↑返回顶部↑