简体   繁体   English

如何“内部加入”两个网站数据库

[英]How to “inner join” two website DB's

I have a requirement and would like to know the best way of achieving the goal. 我有一个要求,并且想知道达成目标的最佳方法。

The idea is to "inner join" two tables from two databases from two completely different websites. 这个想法是从两个完全不同的网站的两个数据库中“内部联接”两个表。

For example, I have a website that tables ID's from another source. 例如,我有一个网站,该网站列出了另一个来源的ID。 I then want to analyse those ID's in more detail by joining my table with the other websites table. 然后,我想通过将我的表与其他网站表联接来更详细地分析那些ID。

My initial thought would be to pass a JSON list of ID's from my table to a php file on the 3rd party host, which would then do a "select fields from table where id in (JSONList)", then pass back the information of which I would then stitch together and display. 我最初的想法是将ID的JSON列表从我的表传递到第三方主机上的php文件,然后执行“从(JSONList)中的ID中选择表中的字段”,然后传递其信息然后,我将缝合并显示。

Is there a better / easier way of doing this? 有没有更好/更轻松的方法?

You can do it directly in the database, which allows you to use sql. 您可以直接在数据库中执行此操作,从而可以使用sql。

MySql will allow you to create a Federated Table locally, that when accessed will pull the data automatically from the remote database. MySql允许您在本地创建联合表,该表在被访问时将自动从远程数据库中提取数据。

Once you've got your federated table setup you should be able to write your join normally eg: 一旦完成了联邦表的设置,您就应该能够正常编写联接,例如:

select * from table1 inner join table2 on table1.joinkey = table2.joinkey;

There are a number of related questions already if this is the approach you wish to take (or at least try): 如果这是您希望采用的方法(或至少尝试使用),则已经存在许多相关问题:

MySQL: SELECT from another server MySQL:从另一台服务器选择

I need to join table from other database and sometimes other server 我需要从其他数据库(有时是其他服务器)联接表

https://dba.stackexchange.com/questions/81411/select-in-federated-table-is-to-slow https://dba.stackexchange.com/questions/81411/select-in-federated-table-is-to-slow


Unfortunately the docs say this will only currently work for mysql to mysql: http://dev.mysql.com/doc/refman/5.1/en/federated-create-connection.html 不幸的是,文档说这目前仅适用于mysql到mysql: http : //dev.mysql.com/doc/refman/5.1/en/federated-create-connection.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM