简体   繁体   中英

Execute one MySQL query on multiple databases

I have a simple question that keeps me up all night :( .

Suppose we have 2 databases on different servers. You can easily create 2 connections and manipulate data in both databases.

What if I want to execute one query on both databases?

Example :

INSERT INTO database1.table1 
VALUES ( 'one','two','three') 
WHERE database1.table1.something LIKE (SELECT something from database2.table2)

Sorry for my code, I'm not really experienced with SQL code.

Such attempts are possible when the databases are all accessible through the same connection.

But is it possible to achieve the same result if the databases are on separate servers (when you need two connections) ?

It would be so much easier for me if such a solution would exist :( .

best regards

Well, it's possible over one connection (Well, one connection from the client to one of the servers. There'll be connections from the server to the other servers). Just use the FEDERATED storage engine . It'll work the way you want (but beware it'll likely be quite slow due to all the added parsing and network traffic)...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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