Kirin Operating System - Open port 3306: Quickly do it in 3 simple steps (open port 3306 in Linux)

Open port 3306 in Linux: do it quickly in 3 simple steps

Way 1

The MySQL server uses the default port 3306, which is responsible for MySQL connections. Therefore, when configuring the MySQL service, it is recommended to allow port 3306 to connect to allow remote users to access MySQL. Here we introduce how to operate the configuration on the Linux server and open port 3306 as easily and quickly as possible.

Step 1: Check whether port 3306 is open

To open port 3306 in the Linux server , first confirm whether it is open. You can use the netstat command to view:

 netstat -tunlp | Grip 3306

[root@localhost ~]# netstat -tunlp | grep 3306    
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 8186/mysqld

As checked by the above command, the 3306 port of this machine is already in the listening state, so the following two steps can be ignored.

Step 2: Start port 3306

If the netstat command is not detected. It means that the current port has not been opened yet. You can use the systemctl command to start:

[root@localhost ~]# systemctl start mysqld.service

Step 3: Configure firewall rules

In order to achieve remote access to the MySQL service, a rule needs to be added to the firewall:

[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp    
success
[root@localhost ~]# firewall-cmd --reload    
success

Use the netstat command above to check whether port 3306 has been opened successfully. As long as you follow the steps mentioned above step by step, you can quickly open port 3306 on the Linux server to achieve remote access to the MySQL service.

Way 2

Execute these three commands directly, and then test whether navicat, etc. can connect outside.

If it is not connected, it may not be a firewall problem. You also need to check whether the mysql root user has enabled remote access permissions.

[root@localhost mysql]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@localhost mysql]# firewall-cmd --reload
success
[root@localhost mysql]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh dhcpv6-client
  ports: 3306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

Guess you like

Origin blog.csdn.net/qq_39535439/article/details/134694463