如何从不同的服务器连接到 mysql 数据库?
比方说,我有一个根网站,在远程服务器上有 mysql 数据库。
我想从许多其他小网站(权限较低)连接到该特定数据库(以进行查询)。
这可以做到吗?
语言:jsp、java、php
I have, let's say, a root website with mysql db on a remote server.
I want to connect to that particular database (to make queries), from many other little websites (with lower priviledges).
Can this be done?
Language: jsp, java, php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果MySQL服务器在你的控制之下,那并不困难;您可以找到该过程 这里。如果不是,你唯一能做的就是请求管理员这样做,否则这是不可能的。
If the MySQL server is under your control, it's not difficult; you can find the procedure here. If it's not, the only thing you can do is beg the admin to do it, otherwise it's impossible.
有什么特别的问题吗?只需在连接字符串中指定服务器地址而不是“localhost”。
您还可以为此创建具有最小权限的专用用户。
Any particular problem? Just specify server address instead of 'localhost' in connection string.
You can also create dedicated user with minimal privileges for that.
默认配置通常包含一个变量
,您需要注释掉该变量才能启用网络。
The default configuration often contains a variable
which you need to comment-out in order to have networking enabled.
是的,可以做到,MySQL 允许来自远程主机的连接(假设 MySQL 配置为允许网络连接并假设远程主机已被授予)。如果出现问题,请参阅 5.4.7 部分。拒绝访问错误的原因列出了最常见的问题和解决方案。
Yes it can be done, MySQL allows connections from remote hosts (assuming MySQL is configured to allow network connections and assuming the remote hosts are granted). In case of problem, the section 5.4.7. Causes of Access-Denied Errors lists most common problems and solutions.
除了 Nikita Rybak 和 Pascal Thivent 的回答之外,我想指出的是,大多数托管提供商不允许从本地主机以外的位置进行查询。
我不知道您对服务器配置有多少访问权限,但是当我第一次开始尝试跨域/服务器的连接时,我会让自己感到头痛。
In addition to the answers from Nikita Rybak andPascal Thivent, I'd like to note that most hosting providers don't allow queries from locations other than localhost.
I don't know how much access you have to the server configuration, but I would have saved myself a headache a while back when I first started experimenting with connections across domains/servers.