Running multiple WordPress installations using the same MySQL Database

imageDid you know that you can host multiple WordPress installations on the same MySQL database? If no, then this article is for you.

There can be many benefits of hosting multiple WordPress installations on the same MySQL database. Usually hosting providers have a limit of how many databases you are allowed to create with their service. Or, it may become too cumbersome to maintain multiple databases. Or, you may want to group together related blogs under the same physical database. Regardless of what your requirement is, it takes very little to host multiple installations on one database.

wordpress configAll it takes is a small change to the wp-config.php file for your blog. Take a look at the screen shot of a wp-config.php file:

Notice the highlighted area. By default the value of $table_prefix is ‘wp_’.

You can set this value to anything you want. The trick is to do this before you install WordPress. If you set the prefix to something which is specific to the blog that you are installing, then WordPress will automatically create the tables for that blog with the proper prefixes.

This allows you to install as many blogs as you want on the same database. So, if you wanted to install another blog on this database, you would simply give another prefix to the second blog.

I use this method all the time. Because when I do this, I don’t need to backup each blog individually. I simply backup one single database and all my blogs get backed up.

Note, this shouldn’t be confused with WordPress MU, which is totally different beast all together. This is for installing WordPress single user, but multiple instances of it.



You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

15 Responses to “Running multiple WordPress installations using the same MySQL Database”

  1. Interesting that you wrote about this… If you want multi-user blogging and multi-blog support I suggest checking out Lyceum. This is a shameless plug because I was involved in the initial development & design when I was a Research Assistant at ibiblio / UNC. Lyceum is based on Wordpress and scales better than Wordpress MU.
    Thats just my $0.02 / INR 2 :)

  2. @Sayan, I have taken a look at Lyceum before when I was evaluating options for use at work. I didn’t know you had worked on it, else I would have asked you :)

  3. Now you know :) I would be glad to put you in touch with my friend John ‘JJB’ Bachir who is the lead developer of Lyceum.

  4. Sayan… next time I go hunting for a CMS, I am getting in touch with you. :)

  5. hi,

    / You can set this value to anything you want. The trick is to do this before you install WordPress. /

    Ok, but how to change before instalation if I have no this file wp-config.php

    can you please tell me with few steps how to do it

    Thanks

  6. @kolio - you have to have a wp-config.php file, if you have freshly downloaded the wordpress installer, then this file is called wp-config-sample.php and you need to rename it to wp-config.php.

    Refer to the installation steps defined on wordpress.org.

  7. [...] Running multiple WordPress installations using the same MySQL Database Easy and awesome for those with db limits [...]

  8. I have a wordpress 2.5.1 site with an existing
    database of articles. When I set up additional sites
    to use the existing DB of articles, will I need to
    use the same ‘DB_NAME’, ‘DB_USER’ and ‘DB_PASSWORD’
    in each wp-config.php file?
    When I give each new site a different table prefix,
    will I also have to give the original site a prefix?
    Will this make me loose my original DB?
    Will I have to start with all new blogs before I
    add any articles to get them to all work with the
    same DB?

    I’m new to all this and would appreciate any help.

    Thanks, pappy

  9. Hi Pappy,

    Use the same db_name, db_user, db_password, etc… the only thing you should change for the new blog is the prefix.

    The original site should stay the same (you don’t need to change anything in that).

    Let me know if you need more help on this.

    Cheers.

  10. Thanks for your reply.

    Will the existing categories and articles on the old site automatically be displayed on the new sites or will I have to create the categories manually?

    Will any new articles posted to one site automatically show up on all my sites using the same DB?

    Thanks,

    pappy

  11. @Pappy… nopes, they will be totally two different blogs (as if you had used two different databases)…

  12. How can I get the same info to show up on 2 different websites?

    Thanks

    Pappy

  13. There is no direct and easy way… sorry…

  14. @Pappy: You have to do a “Domain Redirect”. Google the term, you would get loads of info.
    Happy blogging.

  15. By the way, you can use this for all kinds of sites.

Leave a Reply