MySQL opens remote access and firewall open port 3306 under Linux

Source: Internet
Author: User
Tags iptables

Turn on MySQL remote access permission

The default MySQL user does not have remote access permission, so when the program is not on the same server as the database, we need to turn on MySQL remote access.

There are two main ways to change the table method and the authorization law.

Relatively speaking, it is easier to change the table method, the individual is also more inclined to use this method, so, here only to paste the table method

1. Log in to MySQL

Mysql-u root-p

2. Modify the user table of the MySQL library and change the host entry from localhost to%. % here is to allow any host access, if only one IP access, you can change to the corresponding IP, such as can be changed to 192.168.1.123, this means that only allow LAN 192.168.1.123 this IP remote access to MySQL.

mysql> use mysql;mysql > Update user set host = '% ' where user = ' root '; MySQL> Select Host , user from user; MySQL> Flush privileges;

Firewall Open 3306 Port

1. Open the firewall configuration file

VI  /etc/sysconfig/iptables

2. Add the following line

-A input-m state--state new-m tcp-p TCP--dport 3306-j ACCEPT

3. Restart the firewall

Service  iptables Restart

Note: The added open 3306-port statement must be preceded by the icmp-host-prohibited

Attached: Personal configuration

#Firewall configuration written by System-config-firewall#Manual Customization of this file are 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--stateNEW-M tcp-p TCP--dport 22-J ACCEPT-A input-m State--stateNEW-M Tcp-p TCP--dport 80-J ACCEPT-A input-m State--stateNEW-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

MySQL opens remote access and firewall open port 3306 under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.