来自不同域的mysql连接 [英] mysql connection from a different domain
问题描述
我有网站example.com
,它包含一个MySQL服务器.我还有另一个example.org
,两者都是不同的域.我想从example.org
访问example.com
上的MySQL服务器.怎么可能?
调用数据库连接初始化函数时,需要设置远程example.com
.例如:
mysqli_connect("example.com", 'username', 'password', 'database name');
但是您将需要检查example.com
的MySQL服务器是否设置为接受来自其他主机的连接(请参见my.cnf
或my.ini
中的bind-address
指令),以及username
设置为与之连接",以便能够从外部域进行连接.
请考虑以下phpMyAdmin的 Users 页面: >
很明显,只有用户test
可以从外部域访问( Host 字段中的%
).未在图像上显示,但是用户test
在名为test
的数据库上具有完全特权.即使将服务器设置为接受来自外部的连接,其他用户也将绑定到本地域,但在进行身份验证时,用户将被拒绝.
I have website example.com
, it contains a MySQL server. I have another example.org
, both are different domains. I want to access the MySQL server on example.com
from example.org
. How would it be possible?
You will need to set the remote example.com
when you call the database connection initialization function. For example:
mysqli_connect("example.com", 'username', 'password', 'database name');
But you will need to check whether example.com
's MySQL server is set to accept connections from other hosts (see the bind-address
directive in your my.cnf
or my.ini
), and that the username
you connect with is set to be able to connect from external domains.
Consider the following Users page of phpMyAdmin:
It is clear that only user test
has access from outside domains (%
in the Host field). Not shown on the image, but user test
has full privilege on the database called test
. The other users are bound to the local domain, even though the server is set to accept connections from the outside, when authenticating, users are thrown a denial.
这篇关于来自不同域的mysql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!