Running multiple WordPress installations using the same MySQL Database
Did 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.
All 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.
If you enjoyed reading this blog, consider subscribing to the RSS feed. You can also subscribe to it by email. You can also follow me on Twitter. Thank you!
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.





April 15th, 2008 at 9:09 pm
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
April 15th, 2008 at 11:21 pm
@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
April 16th, 2008 at 1:08 am
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.
April 16th, 2008 at 1:18 am
Sayan… next time I go hunting for a CMS, I am getting in touch with you.
May 13th, 2008 at 4:23 pm
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
May 13th, 2008 at 5:35 pm
@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.
June 20th, 2008 at 6:53 am
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
June 20th, 2008 at 8:56 am
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.
June 20th, 2008 at 5:50 pm
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
June 20th, 2008 at 6:13 pm
@Pappy… nopes, they will be totally two different blogs (as if you had used two different databases)…
June 20th, 2008 at 7:12 pm
How can I get the same info to show up on 2 different websites?
Thanks
Pappy
June 21st, 2008 at 2:12 am
There is no direct and easy way… sorry…
July 5th, 2008 at 4:20 am
@Pappy: You have to do a “Domain Redirect”. Google the term, you would get loads of info.
Happy blogging.
July 5th, 2008 at 4:24 am
By the way, you can use this for all kinds of sites.
July 24th, 2008 at 1:42 am
Thanks, man, this simple post saved me time googling!
October 3rd, 2008 at 2:58 am
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.
October 3rd, 2008 at 10:20 am
@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.
November 28th, 2008 at 5:33 am
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.
November 29th, 2008 at 5:55 pm
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.
March 16th, 2009 at 5:37 pm
Thanks for the article, I have been looking for articles about this to have a better understanding about it.
March 30th, 2009 at 2:42 am
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!
March 30th, 2009 at 3:15 pm
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).
May 20th, 2009 at 11:53 am
Hi,
Great tutorial. This is just what I needed. Thanks!
Take care.
Zoran
July 22nd, 2009 at 1:56 am
Thank you for lesson, buddy! That info was very helpfully.