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.


34 thoughts on “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. 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

  5. @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.

  6. 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

  7. 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.

  8. 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

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

  10. thats part of the code but in 2.6.2 you need to add more code to capabilites.php as the code you mentioned will not copy user roles meaning on second blog you will get page permission issues.

  11. @jc – i am not sure what you mean. this technique doesn’t involve copying anything over to the second blog. All it does is that it allows you to use one database by multiple installation of WordPress.

  12. Hi I already have one instance of WordPress running which I installed using Fantastico but I need to add another blog using the same database as I have no more databases left. Fantastico won’t let me install on the same database as it wants to give it a whole new one. Therefore it looks like I have to manually install WordPress so can you help me with this please?

    I think these are some of the steps I would need to take:

    Download wordpress
    Rename wp-config-sample.php to wp-config.php.
    Change default $table_prefix of ‘wp_’ in the wp-config.php file from default wp to say ‘xx_’
    Update config file with details of db_name etc
    Upload wordpress to server
    Set permissions

    Am I on the right track here. Seems like a lot of effort to get this working or am I making it hard work.

  13. Hello bk,

    Yes, you are doing good. A couple of obvious things just so you are clear:
    1. The new wordpress will be in a separate directory/folder/path than the original one.
    2. You will still need to install WordPress (but that will happen on its own, when you first try to access it on your server).

    If you run into trouble, let me know.

    Cheers.

  14. Vaibhav,

    Hi, I am mostly new to web publishing but have known for four years that WordPress would be the way to go. I have had a bit of experience FTP’ing files to a Unix account at school a couple years ago and having the pages appear on the web. I am comfortable tweaking .ini type files if given the how-to directions.

    I have 3 domains reserved, each for a weblog. I will signup soon with a hosting company. I like to plan carefully and well at the start and am reading about WordPress. I understand most of the basics and concepts of what I am reading about so far.

    But…

    Could you help me understand the difference, if any, between these two concepts:

    - a single WordPress install to be used for multiple blogs (VIrtual Multiblog; WP-Hive)
    - multiple WordPress installations on the same MySQL database (your post)

    The first implies that the newbie would typically have a unique (repeated) WP install for each blog but can get around that; the second sounds like you can have several blogs using a single database.

    Are these two things distinct and different considerations or are they identical situations just expressed in different words? — If they are different, please describe the differences and which of these 2 categories is the more fundamental and primary/preliminary consideration and decision.

    Any guidance in the thought process for deciding these two things would helpful.

    PS – How many Megabytes does “a WordPress install” tend to be before you start adding blogpost content to it?

    Thanks in advance!

    1. Hi William, I have sent you a more detailed reply on email. But here’s the crux of my answer:

      - What I describe is essentially equivalent to separately installed blogs. The only thing you are avoiding is to create a separate database for each one.

      - WordPress MU (multiuser) on the other hand is a single installation which allows you to have multiple blogs on that single installation. It allows you to administer all the blogs centrally.

      I have never noticed how heavy a WordPress install is (I think it is in the region of 2-3 megabytes).

    1. Are these going to have the same content, just different look and feel (and URL, I assume)? If yes, then I don’t think so. The WP database will only work with one URL.

      Although, I am guessing that you can probably customize the WordPress installation itself to support what you are doing (so that it loads different themes depending on where the user is coming from).

  15. I have a site I am creating that will have 3 different language versions.

    For whatever reason we are intending to create 3 different wordpress sites all running under the same domain name and off one database.

    e.g.

    http://www.domainname.com/ (this will be the default UK site)
    http://www.domainname.com/russia
    http://www.domainname.com/czech

    Should I just create new wordpress installs in the directories above e.g. russia and then change the table prefix for each one?

    The webhost automatically installs wordpress – will this cause a problem?

    Thanks in advance for your help. Great post!

    Chris

    1. If I was in your place, I would do the same thing – i.e. install multiple wordpress installations but point them to the same database, just with different prefix. Also, I wouldn’t prefer using the webhost’s automatic scripts to install, since it will probably create three separate databases.

      Here are some points to consider however:
      - the reason I would do this in one database is because it makes it easier for me to manage backups.
      - some hosts charge you per database
      - the reason I wouldn’t do it per database is if your websites are going to become very popular, then one database may not be enough, and it might slow everything down.

      Finally, if the three sites are going to have the same content, then why aren’t you considering a multi-lingual plugin? Search google for “wordpress multilingual plugin”.

      1. Hey,
        Thanks for this.
        Yep we wanted to use a multi-lingual plugin but they just don’t work well enough yet – the translation from English to Russian was awful and the client rejected it – so its easier to create 3 websites.
        It also enables the client to tailor content for each site audience.
        Thanks,
        Chris

  16. will it be easy/possible to uninstall just one version of wordpress later on? I just need the second one to try some stuff out.

    1. Well Matt, depends on what you call easy. It is a simple matter of deleting the web files, and the tables for the second installation which will be clearly marked because of the prefix.

      Your first installation is not affected in anyway.

Comments are closed.