问题描述
我看到很多有关在拒绝或失败连接时如何将客户端连接到MySQL服务器的查询.为了将来简化响应,我将在IP和MySQL级别发布一个简单的连接需求图.必要时,我将在每个部分添加说明.
I see a lot of queries about how to connect a client to a MySQL server when the connection is refused or unsuccessful. In the interest of simplifying responses in the future, I am going to post a simple diagram of connection needs at the IP and MySQL Level. I will add description to each section when need be.
推荐答案
要从客户端计算机连接到MySQL数据库,数据必须遍历多达5个级别的验证.在一般情况下,客户端和服务器不在同一网络上,并且未使用安全连接:
To connect from a client machine to a MySQL DB, the data has to traverse up to 5 levels of validation. Here's a general case where the client and server are not on the same network and a secure connection is not used:
首先请确保MySQL使用的bind-address
与localhost
不同,因此它使用的是接口,而不仅仅是本地连接.
First make sure MySQL is using a bind-address
that is different from localhost
so it uses an interface and not just local connections.
在每个级别,防火墙规则/权限都必须允许连接通过.请注意,一台机器内部的IP可能经常与外部的IP不同.基本原理是:
At each level, the firewall rules/permissions have to allow the connection to go through. Note that a machine can and often has a different IP internally than externally. The basic principle is:
大多数情况下,防火墙配置正确.最后一块通常缺少外部用户对DB
的MySQL服务器GRANT
许可.最后一种语法是:
Most of the time, the firewalls are properly configured. The last piece often missing the the MySQL server GRANT
ing permission to the DB
for the external user. The last syntax is:
通常采用以下形式:
GRANT ALL ON <DB>.* TO '<external_user>'@'<external_ip>' IDENTIFIED BY 'external_password';
这篇关于成功将客户端连接到MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!