Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Database Link - MySQL Equivalent?

Tags:

mysql

oracle

Oracle's database link allows user to query on multiple physical databases.

Is there any MySQL equivalent ? Workaround ?

I want to run a join query on two tables , which are in two physical databases. Is it possible in MySQL ?

like image 330
Palani Avatar asked Oct 14 '09 12:10

Palani


People also ask

What is a DB link in Oracle?

A database link is a pointer that defines a one-way communication path from an Oracle Database server to another database server. The link pointer is actually defined as an entry in a data dictionary table. To access the link, you must be connected to the local database that contains the data dictionary entry.

What is DB Link MySQL?

A database link is a schema object in one database that enables you to access objects on another database. The other database need not be an Oracle Database system.

Can I connect to Oracle Database with MySQL?

It is possible to connect Oracle to MySQL using a feature within Oracle known as Heterogeneous Services. This allows you to use database links within Oracle to connect to non-Oracle databases, such as MySQL, via ODBC. You will need to create your own tables in MySQL before running inserts across the database link.


2 Answers

I can think of four possible workarounds for your scenario:

  1. use fully-qualified-table-names when querying for the external table. MySQL supports the dbname.tablename-syntax to access tables outside the current database scope. This requires that the currently connected user has the appropriate rights to read from the requested table in another physical db.
  2. if your external database is running on a different MySQL server (either on the same machine or via a network connection) you could use replication to constantly update a read-only copy of the remote table. Replication is only possible if you're running two separate MySQL instances.
  3. use the FEDERATED MySQL storage engine to virtually import the table into your current database. This lifts the requirement of giving the current user access rights into the second database as the credentials are given with the CREATE TABLE-statement when using the FEDERATED storage engine. This also works with the databases running on different physical servers or different MySQL instances. I think that this will be the poorest performing option and does have some limitations - more or less important depending on your usage scenario and your requirements.
  4. This is an extension to method 1. Instead of having to specify the fully-qualified-table-names every time you request information from your external table, you simply can create a view inside your current database based on a simple SELECT <<columns>> FROM <<database>>.<<table>>. This resemble the way, the FEDERATED-method works, but is limited to tables on the same MySQL instance.

Personally I'd consider method (4) as the most useful - but the others could also be possible workarounds depending on your requirements.

like image 77
Stefan Gehrig Avatar answered Sep 22 '22 04:09

Stefan Gehrig


There's no MySQL equavilent method at the moment, see this post. However as the poster suggest you can do a work-around if the databases are on the same machine, by just adding the database-name in front of the table-name.

Also see this, it's 6 years old, but still not resolved. It's closed and probably not on their todo-list anymore.

like image 45
Filip Ekberg Avatar answered Sep 21 '22 04:09

Filip Ekberg