1

In my Drupal 7 installation I have:

  1. Main site: example.com
  2. Sub Domains: blog.example.com, forum.example.com (all in same domain)

I have database design in such a way:

  • Main Site uses: main_db
  • Sub Domain uses: blog_db, forum_db (all separate databases)

When the user register's in main site, they should also able to use other sub-domains without registering again and again. I can copy/sync the users table from main_db to other dbs, but that not suitable solution. as it creates 3 instances of same data.

Is there any solution to store users table in main_db and access it via other dbs ? The proper term would be, how to share the users table from main database to other databases.

1 Answers1

2

You can query from other databases in MySQL. Simply prefix the database in front of the table name.

This is from documentation of the SELECT statement:

You can refer to a table within the default database as tbl_name, or as db_name.tbl_name to specify a database explicitly.

Just make sure you edit the permissions so that your user can access the required databases.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • thanks for the answer. Just a question, do you think it'll slow my database while fetching the result from multiple databases ? –  Feb 11 '13 at 15:13
  • According to this previous answer, there is no performance penalty for querying across databases: http://stackoverflow.com/questions/3224136/performance-of-querying-across-two-mysql-databases-on-the-same-server – Marcus Adams Feb 11 '13 at 20:27