Home » Performance » MySQL » Join tables across database
Join tables across database [message #680] Wed, 07 February 2007 10:56 Go to next message
al.james  is currently offline al.james
Messages: 16
Registered: October 2006
Junior Member
Hi there...

I am building a couple of websites. The idea is that the two (later to be more) sites share some info such as user accounts.

Now, I want to use a separate database for each website, but how would I manage to link the user tables?

Currently all the databases exist on the same server, so I beleive it would be possible to keep the joint data in its own database and be able to access it in database.table.column notation.

However, would I pay a performance hit doing it this way? In particular if I were performing joins across databases?

Is there another way to do it. I.e. could I create a virtual table in one database that is a linked copy one from the other database.

Also, if the database grows beyond a single server, I guess I could use replication to do this?
Re: Join tables across database [message #683 is a reply to message #680 ] Wed, 07 February 2007 15:30 Go to previous messageGo to next message
al.james  is currently offline al.james
Messages: 16
Registered: October 2006
Junior Member
Just had a thought. Might be crazy, but:

I have two databases, A and B that have application specific data. I have database C that has shared data (users).

Could I use federated tables from database A or B to connect to the tables in database C? Can I do this even though all databases exist on the same mysql instance?
Re: Join tables across database [message #689 is a reply to message #683 ] Thu, 08 February 2007 06:31 Go to previous messageGo to next message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Hm,

If it is same instance you can simply join tables from different databases such as

select * from db1.tbl1 join db2.tbl2 on tbl1.id=tbl2.id


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Re: Join tables across database [message #691 is a reply to message #689 ] Thu, 08 February 2007 07:22 Go to previous messageGo to next message
al.james  is currently offline al.james
Messages: 16
Registered: October 2006
Junior Member
hi there... Thanks for the reply. Would I pay performance hit for doing that?
Re: Join tables across database [message #692 is a reply to message #691 ] Thu, 08 February 2007 08:21 Go to previous message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
About same as accessing files in different directories.

Nothing to worry about.


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Previous Topic:GROUP BY with ORDER BY without using filesort/tmp table
Next Topic:Duplicate Key Problem
Goto Forum:
  


Current Time: Sun Jul 5 16:14:26 EDT 2009

Total time taken to generate the page: 0.01206 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.