記錄一下
轉自:
https://blog.51cto.com/itafei/1943914
centos 6.8啟動mysql CentOS7和CentOS6怎樣開啟MySQL遠程訪問
1.開放mysql訪問端口3306
修改防火牆配置文件
vi /etc/sysconfig/iptables
加入端口配置
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
如果有下面一句話,直接刪掉:
-A INPUT -p tcp -m tcp --dport 3306 -j DROP
重新加載規則
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這個版本的防火牆默認使用的是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一樣
CentOS下防火牆的基本操作命令
CentOS 配置防火牆操作實例(啟、停、開、閉端口):
注:防火牆的基本操作命令:
查詢防火牆狀態:
[root@localhost ~]# service iptables status<回車>
停止防火牆:
[root@localhost ~]# service iptables stop <回車>
啟動防火牆:
[root@localhost ~]# service iptables start <回車>
重啟防火牆:
[root@localhost ~]# service iptables restart <回車>
永久關閉防火牆:
[root@localhost ~]# chkconfig iptables off<回車>
永久關閉后啟用:
[root@localhost ~]# chkconfig iptables on<回車>
1、查看防火牆狀態
[root@localhost ~]# service iptables status<回車>
2、編輯/etc/sysconfig/iptables文件。我們實例中要打開8080端口和9990端口
用編輯器打開/etc/sysconfig/iptables
4、保存/etc/sysconfig/iptables文件,並在終端執行
[root@localhost ~]# service iptables restart <回車>
5、從新查看防火牆狀態
[root@localhost ~]# service iptables status<回車>
6、這時候,服務器的8080和9990端口就可以對外提供服務了。
7、其他端口的開放模式就是類似如此開放模式。