Reasons and solutions for being unable to remotely connect to MySQL database under CentOS7

Reasons and solutions for being unable to remotely connect to MySQL database under CentOS7

Preface

I recently encountered a problem at work. I found that I could not remotely connect to MySQL under the Centos7 system. I finally solved it by searching for relevant information. The following method is what I tried after I encountered the problem of not being able to connect to the Mysql database remotely, and it finally solved the problem. So I summarize and share it for reference and learning for friends who encounter the same problem. I won’t say much below, let’s take a look at the detailed introduction.

There are two reasons

  • The database is not authorized
  • The server firewall does not open port 3306

1. The database is not authorized

There is no authorization for the MySQL database, so just one command is enough.

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;


//When connecting to the database remotely, you need to enter the username and password Username: root
Password:123456
Point to ip:% to represent all IPs. You can also enter IP here to specify IP.

To make the changes take effect, you also need the following statement mysql>FLUSH PRIVILEGES;

2. The server firewall does not open port 3306

CentOS has two firewalls: FirewallD and iptables firewall

centos7 uses the FirewallD firewall.

FirewallD is a front-end controller for iptables that implements persistent network traffic rules. It provides both command line and graphical interfaces and is available in the repositories of most Linux distributions. There are two main differences when using FirewallD compared to controlling iptables directly:

1. FirewallD uses zones and services instead of chained rules.

2. It dynamically manages rule sets, allowing rules to be updated without disrupting existing sessions and connections.

FirewallD is a wrapper around iptables that allows you to manage iptables rules more easily - it is not a replacement for iptables. Although iptables commands can still be used with FirewallD, it is recommended that you use only FirewallD commands when using FirewallD.

1. Open port 3306 on FirewallD

 firewall-cmd --zone=public --add-port=3306/tcp --permanent

Command meaning:

--zone #scope --add-port=3306/tcp #Add port, format: port/communication protocol --permanent #Permanent, without this parameter, it will be invalid after restart

Restart the firewall

systemctl restart firewalld.service

2.iptables development port 3306

/sbin/iptables -I INPUT -p tcp -dport 3306 -j ACCEPT

/etc/rc.d/init.d/iptables save

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed steps to install MYSQL8.0 on CentOS7.6
  • Tutorial on installing MySQL 5.7.28 on CentOS 6.2 (mysql notes)
  • MySQL 8.0.16 installation and configuration tutorial under CentOS7
  • Detailed tutorial on installing mysql 8.0.13 (rpm) on Centos7
  • CentOS7 uses yum to install mysql 8.0.12
  • Detailed steps for installing and configuring MySQL 8.0 on CentOS
  • CentOS7 installation GUI interface and remote connection implementation
  • Tutorial on installing MySql5.7 in CentOS7.2 and enabling remote connection authorization
  • How to install MySql in CentOS 8 and allow remote connections

<<:  Sample code for converting video using ffmpeg command line

>>:  Complete steps to install FFmpeg in CentOS server

Recommend

Graphical steps of zabbix monitoring vmware exsi host

1. Enter the virtualization vcenter, log in with ...

Three ways to configure JNDI data source in Tomcat

In my past work, the development server was gener...

Solutions to common problems using Elasticsearch

1. Using it with redis will cause Netty startup c...

How to manually encapsulate paging components in Vue3.0

This article shares the specific code of the vue3...

Teach you how to use Portainer to manage multiple Docker container environments

Table of contents Portainer manages multiple Dock...

Four ways to create objects in JS

Table of contents 1. Create objects by literal va...

Several techniques for playing sounds with CSS

CSS is the realm of style, layout, and presentati...

Top 10 useful and important open source tools in 2019

In Black Duck's 2017 open source survey, 77% ...

Implementation of rewrite jump in nginx

1. New and old domain name jump Application scena...

Solve the problem after adding --subnet to Docker network Create

After adding –subnet to Docker network Create, us...

SQL implements LeetCode (180. Continuous numbers)

[LeetCode] 180. Consecutive Numbers Write a SQL q...

How to configure jdk environment under Linux

1. Go to the official website to download the jdk...

jQuery implements the drop-down box for selecting the place of residence

The specific code for using jQuery to implement t...

Example of how to quickly build a LEMP environment with Docker

LEMP (Linux + Nginx + MySQL + PHP) is basically a...