Enable remote access rights for MySQL under Linux and open port 3306 in the firewall

Enable remote access rights for MySQL under Linux and open port 3306 in the firewall

Enable remote access rights for mysql

By default, MySQL users do not have remote access permissions, so when the program and the database are not on the same server, we need to enable remote access permissions for MySQL.

There are two mainstream methods, the table modification method and the authorization method.

Relatively speaking, the table modification method is easier, and I personally prefer this method. Therefore, I will only post the table modification method here.

1. Log in to MySQL

mysql -u root -p

2. Modify the user table of the MySQL database and change the host item from localhost to %. %This means that any host is allowed to access. If only a certain IP is allowed to access, you can change it to the corresponding IP. For example, you can change localhost to 192.168.1.123, which means that only the IP 192.168.1.123 in the local area network is allowed to remotely access MySQL.

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

Open port 3306 on the firewall

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 statement to open port 3306 must be placed before icmp-host-prohibited

Attachment: Personal configuration

# 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-prohibited
COMMIT

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to mysql connection blocked by firewall under linux
  • Solution for adding iptables firewall policy to MySQL service

<<:  JavaScript implementation of drop-down list

>>:  foreman ubuntu16 quick installation

Recommend

Using react-virtualized to implement a long list of images with dynamic height

Table of contents Problems encountered during dev...

Detailed explanation of how to use element-plus in Vue3

Table of contents 1. Installation 2. Import in ma...

CentOS6.8 uses cmake to install MySQL5.7.18

Referring to the online information, I used cmake...

Introduction to new features of MySQL 8.0.11

MySQL 8.0 for Windows v8.0.11 official free versi...

Linux Dig command usage

Dig Introduction: Dig is a tool that queries DNS ...

border-radius is a method for adding rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

Each time Docker starts a container, the IP and hosts specified operations

Preface Every time you use Docker to start a Hado...

Installation and use of mysql mycat middleware

1. What is mycat A completely open source large d...

WeChat Mini Programs Implement Star Rating

This article shares the specific code for WeChat ...

Implementation of HTML sliding floating ball menu effect

CSS Styles html,body{ width: 100%; height: 100%; ...

A brief introduction to VUE uni-app core knowledge

Table of contents specification a. The page file ...

Detailed explanation of the order of JS object traversal

Some of you may have heard that the order of trav...