centos7 打开mysql 3306端口并 设置外部访问

mysql安装后默认是localhost访问,如果需要外部访问可以设置一个新的账号把host改为%,意味着所有ip均可以访问

grant all privileges on *.* to 'outUser'@'%' identified by '12' with grant option

然后

flush privileges;

就可以使用outUser账户密码12来外部访问,有的时候无法访问需要打开防火墙开放端口

centos 7 中使用的是firewall-cmd命令

# firewall-cmd --list-all-zones    #查看所有的zone信息

# firewall-cmd --get-default-zone     #查看默认zone是哪一个

# firewall-cmd --zone=internal --change-zone=p3p1  #临时修改接口p3p1所属的zone为internal

# firewall-cmd --add-service=http    #暂时开放http

# firewall-cmd --permanent --add-service=http  #永久开放http

# firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久开放80端口

# firewall-cmd --permanent --zone=public --remove-service=ssh   #从public zone中移除服务

# firewall-cmd --reload   #重新加载配置

  打开3306端口

firewall-cmd --add-port=3306/tcp --permanent

  ok

 

posted @ 2016-11-22 22:18  xnuwu  阅读(15708)  评论(0编辑  收藏  举报