Quick question: Can I use the same database for my 6 different websites?

ugurbyr

BANNED
Joined
Oct 2, 2021
Messages
283
Reaction score
85
I prepared websites and i exported the databases and backup files, can I use the same databases for my 6 different websites? ( only the post database is unique, other parts of databases are same)
 
You haven't mentioned the script you're using. So for all intents and purposes, I am going to assume that it is WordPress and my answer will be framed accordingly.

So, you want to use the same database for different websites. You believe that wp_post is the only table that is different, while every other table is theoretically the same.

Let me explain why that is not the case -

So a core WordPress installation is built out of 12 tables, these are
  1. wp_posts
  2. wp_postmeta
  3. wp_options
  4. wp_users
  5. wp_usermeta
  6. wp_term_taxonomy
  7. wp_terms
  8. wp_termmeta
  9. wp_term_relationships
  10. wp_links
  11. wp_comments
  12. wp_commentmeta
You can read about them here - https://codex.wordpress.org/Database_Description

Now all of these tables are both independent and interdependent at the same time. Independent, in that editing the content of one specific table (for instance wp_posts will affect a particular post inside that table. Interdependent, because these tables each run parallel at times to display different parts of a WordPress post or page.

Now, for instance, wp_posts saves the content part of your posts, it has an extension table wp_postmeta which stores the meta-information of their corresponding posts. Going forward, wp_terms stores the category of these posts and pages. Furthermore, wp_terms_taxonomy goes ahead and stores the taxonomy - if it is a category, tag or link. Moving ahead, wp_terms_relationships is the one that stores the information of which term is associated with which post (your post is under which category, which tag is applied to the post etc.) So on and so forth...

This should help you understand that wp_posts isn't the only shared category.

Now, if your sites are relatively new, have little content no traffic and you want each of them to connect to a single database (maybe you have limited databases etc.) - what you can do is edit the database prefixes.

See the wp_ before the table name? That is called a database prefix. WordPress lets you choose one when installing and lets you edit them later.

You can also declare them in your wp-config.php like this

PHP:
$table_prefix  = 'site1_';

So theoretically, you can have site1.com with the prefix site1_, site2.com with the prefix site2_, so on and so forth - all connecting to the same MySQL database with the same credentials.

This is, however, not recommended.

We do this in our test environments when testing websites or running a quick fix on errors and we can't be bothered to create a new environment.
 
Last edited:
I'm not a pro here but I see why not?
Just use different prefixes for each site's tables.

Just read the message above... that's what I mean here.
 
what do you mean no? explain please
people who ask this question are not knowledgeable enough about databases and, at some point, they will mess something up and if your DB is screwed and you can't fix it then all of your sites are screwed. That's why it's always recommended to keep every site and every program that you install on its own DB.

I'm not a technical enough guy to explain the intricate details of why this is bad. All I know is that in the past I've ruined many sites (luckily, they have all been mine) so I've learned not to mess with DBs anymore. For more technical details see the post that @BlogPro made. It's amazingly good!
 
Let me explain why that is not the case -
Let me explain what i did: First of all i truncate the wp-post and wp-postmeta and then i get the contents with an automated bot and then i edit the contents and then i export the full database so i export all 12 databases that you talked about above, after i export the database file i again truncate the wp_post and wp_postmeta and then i do the same for my other website projects. im preparing websites like this, i will launch my websites later. Can't I use the same database for all of my different websites?
 
Let me explain what i did: First of all i truncate the wp-post and wp-postmeta and then i get the contents with an automated bot and then i edit the contents and then i export the full database so i export all 12 databases that you talked about above, after i export the database file i again truncate the wp_post and wp_postmeta and then i do the same for my other website projects. im preparing websites like this, i will launch my websites later. Can't I use the same database for all of my different websites?

You framed the question wrong. When you use the term 'database' - it is usually implied that you mean 'database sever'. You should've said 'database dump'.

Let me guess, you have very similar sites with the same architecture and you want to change a few things here and there.

I like the K.I.S.S approach - Keep it Simple, Silly!

A simpler way would be to make edits using a plugin such as Duplicator. This would prevent you from the headache of manually editing the databases.

- Finalize Site1 on the local server
- Export a full duplicator backup, call it Site1
- Make all your edits for Site2
- Export a full duplicator backup, call it Site2
- Repeat until all sites are ready
- One-click restore to your hosts,

A WordPress structure is two-pronged - one is the backend driven content and the other is the front-end driven layout.

If all your sites are going to have the same design etc. or you don't care, you don't even need duplicator. You can make your edits and simply export the posts and restore them to your new sites.

In your current setup, you can try restoring them and see if everything works. You'll end up risking a lot of Database errors and/or mismatch issues.
 
Yes, you can use the same DB. But, it is preferred to use different. Keep a different prefix if you want to use the same DB.
 
You haven't mentioned the script you're using. So for all intents and purposes, I am going to assume that it is WordPress and my answer will be framed accordingly.

So, you want to use the same database for different websites. You believe that wp_post is the only table that is different, while every other table is theoretically the same.

Let me explain why that is not the case -

So a core WordPress installation is built out of 12 tables, these are
  1. wp_posts
  2. wp_postmeta
  3. wp_options
  4. wp_users
  5. wp_usermeta
  6. wp_term_taxonomy
  7. wp_terms
  8. wp_termmeta
  9. wp_term_relationships
  10. wp_links
  11. wp_comments
  12. wp_commentmeta
You can read about them here - https://codex.wordpress.org/Database_Description

Now all of these tables are both independent and interdependent at the same time. Independent, in that editing the content of one specific table (for instance wp_posts will affect a particular post inside that table. Interdependent, because these tables each run parallel at times to display different parts of a WordPress post or page.

Now, for instance, wp_posts saves the content part of your posts, it has an extension table wp_postmeta which stores the meta-information of their corresponding posts. Going forward, wp_terms stores the category of these posts and pages. Furthermore, wp_terms_taxonomy goes ahead and stores the taxonomy - if it is a category, tag or link. Moving ahead, wp_terms_relationships is the one that stores the information of which term is associated with which post (your post is under which category, which tag is applied to the post etc.) So on and so forth...

This should help you understand that wp_posts isn't the only shared category.

Now, if your sites are relatively new, have little content no traffic and you want each of them to connect to a single database (maybe you have limited databases etc.) - what you can do is edit the database prefixes.

See the wp_ before the table name? That is called a database prefix. WordPress lets you choose one when installing and lets you edit them later.

You can also declare them in your wp-config.php like this

PHP:
$table_prefix  = 'site1_';

So theoretically, you can have site1.com with the prefix site1_, site2.com with the prefix site2_, so on and so forth - all connecting to the same MySQL database with the same credentials.

This is, however, not recommended.

We do this in our test environments when testing websites or running a quick fix on errors and we can't be bothered to create a new environment.
This should be a post of its own
 
ugurbyr you are always trying to make things so complicated for yourself. Just keep things simple.
 
Back
Top