The reason why the mysql database cannot be remotely connected in centos 7 is solved.

Source: Internet
Author: User

The reason why the mysql database cannot be remotely connected in centos 7 is solved.

Preface

Recently, I encountered a problem in my work. I found that I could not remotely connect to mysql in Centos7. By searching for relevant information, I finally solved the problem, the following method is used after I try to remotely connect to the Mysql database and finally solve the problem. So let's summarize and share it for the reference and Study of friends who have encountered the same problem. Let's talk about it later. Let's take a look at the detailed introduction.

There are two reasons

  • Database not authorized
  • The server firewall does not open port 3306.

1. The database is not authorized

Mysql database is not authorized. You only need to use one command.

Mysql> grant all privileges on *. * TO 'root' @ '%' identified by '000000' with grant option; // When remotely connecting TO the database, enter the username and password Username: root Password: 123456 ip Address: % indicates all Ip addresses. You can enter an Ip address to specify the Ip address to make the modification take effect. The following statement is also required: mysql> flush privileges;

2. Server Firewall does not open port 3306

Centos has two firewalls: FirewallD and iptables.

Centos7 uses the FirewallD firewall.

FirewallD is the front-end controller of iptables to implement persistent network traffic rules. It provides command line and graphical interfaces, which are available in most Linux distributions. Compared with the direct control of iptables, FirewallD has two main differences:

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

2. It dynamically manages rule sets and allows updating rules without disrupting existing sessions and connections.

FirewallD is an encapsulation of iptables, which makes it easier for you to manage iptables rules-it is not a substitute for iptables. Although the iptables command can still be used for FirewallD, we recommend that you only use the FirewallD command when using FirewallD.

1. The FirewallD Firewall opens port 3306.

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

Command description:

-- Zone # scope -- add-port = 3306/tcp # add a port in the format of "port/communication protocol -- permanent #". If this parameter is not set, the port is invalid after restart.

Restart Firewall

systemctl restart firewalld.service

2. develop port 3306 using iptables

/sbin/iptables -I INPUT -p tcp -dport 3306 -j ACCEPT/etc/rc.d/init.d/iptables save

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Related Article

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.