linux下mysql開啟遠端存取許可權及防火牆開放3306連接埠,mysql3306

來源:互聯網
上載者:User

linux下mysql開啟遠端存取許可權及防火牆開放3306連接埠,mysql3306

開啟mysql的遠端存取許可權

預設mysql的使用者是沒有遠端存取的許可權的,因此當程式跟資料庫不在同一台伺服器上時,我們需要開啟mysql的遠端存取許可權。

主流的有兩種方法,改表法和授權法。

相對而言,改表法比較容易一點,個人也是比較傾向於使用這種方法,因此,這裡只貼出改表法

1、登陸mysql

mysql -u root -p 

2、修改mysql庫的user表,將host項,從localhost改為%。%這裡表示的是允許任意host訪問,如果只允許某一個ip訪問,則可改為相應的ip,比如可以將localhost改為192.168.1.123,這表示只允許區域網路的192.168.1.123這個ip遠端存取mysql。

mysql> use mysql; mysql> update user set host = '%' where user = 'root'; mysql> select host, user from user; mysql> flush privileges; 


防火牆開放3306連接埠

1、開啟防火牆設定檔

vi  /etc/sysconfig/iptables

2、增加下面一行

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

3、重啟防火牆

service  iptables restart

注意:增加的開放3306連接埠的語句一定要在icmp-host-prohibited之前

附:個人配置

# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -i eth0 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT-A FORWARD -p icmp -j ACCEPT-A FORWARD -i lo -j ACCEPT-A FORWARD -i eth0 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.