2

I have a MySQL database on my cPanel, this supports only one DB.
So I have to make 2 web sites on one hosting that has only one DB support, unfortunately I also don't have prefix to my DB. can I merge my two databases into one database?

Max tables in a MySQL database

I searched this but cannot understand, I think this is not a problem I have.

I use php and MySQL.

3 Answers 3

2

You can have multiple ... things ... in your database, as the underlying platform doesn't really care that Site A only accesses tables W,X, and Y, whereas Site B only accesses tables Z and V.

To make such arrangement somewhat sane ("is this table part of Site A, or Site B, or what?"), it is common to prefix the tables inside the (single) database. Some platforms (e.g. the ModX CMS) have this built-in - you set the table prefix during install, and off you go - e.g. any table prefixed a_ would be a logical part of Site A.

If you already have two sites (and two databases), this can get somewhat icky, especially if the table names overlap - you'd need to go into the code for each site, and add the prefix for that site in every place the database is accessed in code. Again, some frameworks allow you to change this prefix.

2

What do you mean by " I also don't have prefix to my DB" ?

Because if you cant't have two databases, the easiest workaround would be to name tables from each application with different prefixes, like app1name_table1, app1name_table2, app2name_table1, app2name_table2, and so on... each application would access its own tables, and it doesn't matter that all tables are in the same schema

2

I wouldn't recommend doing something like that.

Just find a way to get more DBs with your hosting service...

if you can't: consider changing hosting service.

1
  • The table-prefix is indeed a bit of an ugly hack. That said, e.g. most of the "free" hosting providers will only give you 1 database. Aug 30, 2011 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.