MySQL -- 使用 Python 在不同服务器上的数据库之间连接? [英] MySQL -- Joins Between Databases On Different Servers Using Python?

查看:40
本文介绍了MySQL -- 使用 Python 在不同服务器上的数据库之间连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL中,我有两个不同的数据库——我们称它们为AB.

In MySQL, I have two different databases -- let's call them A and B.

数据库A驻留在服务器server1上,而数据库B驻留在服务器server2上.

Database A resides on server server1, while database B resides on server server2.

两台服务器{AB}物理上彼此靠近,但是在不同的机器上并且有不同的连接参数(不同的用户名、不同的密码等).

Both servers {A, B} are physically close to each other, but are on different machines and have different connection parameters (different username, different password etc).

在这种情况下,是否可以在数据库A中的表与数据库B中的表之间执行连接?

In such a case, is it possible to perform a join between a table that is in database A, to a table that is in database B?

如果是这样,我该如何在 python 中以编程方式进行处理?(我使用 pythonMySQLDB 分别与每个数据库交互).

If so, how do I go about it, programatically, in python? (I am using python's MySQLDB to separately interact with each one of the databases).

推荐答案

尝试使用 联邦存储引擎.

解决方法:可以使用另一个 DBMS 在两个数据库之间检索数据,例如您可以使用 MS SQL Server 中的链接服务器来完成(请参阅 sp_addlinkedserver 存储过程).来自文档:

Workaround: it is possible to use another DBMS to retrieve data between two databases, for example you could do it using linked servers in MS SQL Server (see sp_addlinkedserver stored procedure). From the documentation:

链接服务器允许访问针对 OLE DB 数据源的分布式异构查询.

A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources.

这篇关于MySQL -- 使用 Python 在不同服务器上的数据库之间连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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