来自不同域的mysql连接 [英] mysql connection from a different domain

查看:69
本文介绍了来自不同域的mysql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网站example.com,它包含一个MySQL服务器.我还有另一个example.org,两者都是不同的域.我想从example.org访问example.com上的MySQL服务器.怎么可能?

解决方案

调用数据库连接初始化函数时,需要设置远程example.com.例如:

mysqli_connect("example.com", 'username', 'password', 'database name');

但是您将需要检查example.com的MySQL服务器是否设置为接受来自其他主机的连接(请参见my.cnfmy.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆