Forum Moderators: coopster

Message Too Old, No Replies

One or more databases?

PHP/MySQL app uses three databases, want to use one

         

Warboss Alex

8:40 am on Jan 3, 2005 (gmt 0)

10+ Year Member



Hey all, happy 2005!

Just a quick question. My site uses three (potentially four or five databases) MySQLs, having no more than half a dozen tables each (one database just has ONE table). This was done because I wanted to keep different information distinct, and seperate from each other, to reduce database size, and to be somewhat more secure (if one db gets corrupted, the rest don't, heh). I've got a daily backup of these databases, the total size is about 4mb.

The databases hold text, no big blob/file fields as yet. However, they do hold duplicate data, for example I've got a database for 'users' and one for 'forums', but if a user posts on a forum (to the 'forums' database), they need to pull their user data (avatar, custom sig, etc) from the 'users' database. This involves two database connections, and the usual tripe.

Still in the same users/forums example, it'd be easier to have ONE database, but would this be safer/more efficient? I know that now, to retrieve a post, it's just a simple SELECT, since all the data's in the row. If they were in the same database, I'd use a JOIN using the userID in the posts table, plus the options for that post (avatar, sig, blah blah).

What's the recommended practice? I can see which is easier, but would there be a perfomance hit using the JOIN (one which we'd notice, heh)?

And while we're on that subject, how LARGE can a single MySQL database get? My project's fairly small, but could get bigger, I wouldn't like to have it slow down suddenly, because it's working pretty well now. Or would the differences be negligible, unless we get in the thousands of rows league?

Thanks for any help/advice in advance!

Cheers,
Alex ...

Salsa

4:50 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



Gosh, I'm no expert on this, but I wouldn't be tinkering with so many databases for the applications that you mentioned. As to how large a database can be, that's more a limitation of your server, and not of MySQL. According to the MySQL Manual [dev.mysql.com], the size limit for a single MyISAM table is 8 million terabytes! Which means that the real limitation on even the size of a single table is the file size limitation of your OS, and your available physical storage space. But I'm sure that others will have more sage advice.

And back at you: Happy New Year! (It's going to be a good one.)

Warboss Alex

4:54 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



8 million terabytes? Man, I've got 500mb of webspace. I think we're covered. LOL.

Yeah, I'm thinking that I'm being a bit silly with the databases. It's all very well to seperate content, but I think it's unnecessary, the way I've done it here.

Besides, if my host offers six MySQLs, I should really stick to one per domain or something. Since apparently storage isn't an issue! Perfomance is though..

Thanks Salsa! Anyone else?

Salsa

5:01 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



~Laugh~ Nope, I meant 8 million terabytes. Heck, I didn't even type it, I copied and pasted it from the MySQL manual page in the link I offered. Maybe they made a typo?

[edited]Ah, I see that you edited your last post, where you gave me the cheesy grin about 8 million terabytes![/edited]

jollymcfats

5:07 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



I'd agree that you probably don't need so many databases, but it doesn't have to be a performance issue as-is. A single MySQL connection can access and JOIN across all of the databases. This works by adding the database names to the query. FROM db1.table1 NATURAL JOIN db2.table2 etc.

Warboss Alex

6:15 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



(Sheepish grin in Salsa's direction..) .. erm.. yeah.. sorry. hehe.

jollymcfats - I've tried this before, it didn't work for some reason. Can't remember why. But if you're JOIN-ing data (and incurring the overhead), you might as well have it all in one database anyway.. right?

jollymcfats

3:30 am on Jan 4, 2005 (gmt 0)

10+ Year Member



The database user does need to be GRANTed the appropriate permissions on all of the databases and/or tables involved. That's probably not setup by default in a hosting environment.

The number of databases involved doesn't matter in the performance of a MySQL join, though going with fewer databases is simpler- and that may be beneficial in the long run.

In terms of general overhead, I'd think that a typical join query on properly indexed tables would be basically instantaneous compared to the overhead of making 2 seperate database connections and issuing two separate queries. Connection setup and query preparation are relatively expensive.

Warboss Alex

11:58 am on Jan 4, 2005 (gmt 0)

10+ Year Member



Well, everything's been trial and error for the past few years for me, as far as web development's concerned. I'm very adept at PHP, but I've not used MySQL in anything other than very small, personal applications so I guess I'll have to try it and see if the perfomance is better/worse.

Having just ONE database connection per page would probably be a good thing though.