Joining tables in different mySQL databases on same server, different instances

Posted on 2013-12-02
Last Modified: 2015-03-02
We have an application that uses two instances of mysql, running on two different ports on the same server, say 4510 and 4511.  Table "A" has transaction details and a user number, Table "B" (on 4511) has user details.  I need to simply join the two tables to provide all of the transaction details and the associated user name.  Apparently if these two databases were on the same mysql port, this would be pretty simple.  However, I'm not sure how to make it work in this case.

The only thing I've found so far relates to using a federated storage engine and federated table.  Is this the correct (only?) way to do what I need to do?
Question by:Chuck Brown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Author Comment

by:Chuck Brown
ID: 39692549
Sorry, joining two tables isn't the real problem.  Joining two tables in two different databases residing in two different databases that run under two different ports on the same server is the issue.  Thanks for trying!
LVL 35

Accepted Solution

gr8gonzo earned 500 total points
ID: 39692553
Federated storage engine is the only way to do it with native MySQL functionality, but it's not the only way. Honestly, I would likely use some kind of intermediate scripting / programming language to pull the data separately and join it together.

For example, if you were using a .NET language, it would be trivial to create the two separate connections, then pull all the data into separate DataTable objects (optionally use a DataSet object to join them together) and go from there. The same thing could be done in a scripting language, like PHP.
LVL 35

Expert Comment

ID: 39692562
The only downside to the scripted approach is that the final, joined data exists within the scope of the application that did the joining, so that might be good or bad depending on your goals.
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!


Author Comment

by:Chuck Brown
ID: 39692575
Is there a downside to using the Federated Storage Engine?

Author Comment

by:Chuck Brown
ID: 39692593

Thanks.  That may be closer, I'm not sure.  The end result of that solution is (apparently) to grant access between the databases, but doesn't say how that is to be done, nor how to actually do a query between the two once permission is granted.
LVL 35

Expert Comment

ID: 39692609
@virastar - that article uses the intermediate programming/scripting language approach that I mentioned, but pushing the data back into temp tables is likely slower than just using the in-memory data.

@clbrownjr - Aside from initial setup, no, there's no real downside. On the backend, it's technically doing the same thing - it's just using the MySQL client as the intermediate piece instead of a separate application. If you're good with enabling the federated storage, then it should be a fine solution.

Just to set expectations, remember that no matter what you do, you're dealing with two different, separately-optimized tables, so the solution will always be slower than using a single instance containing both tables.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question