Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Two servers, one database
Old 03-01-2005, 02:14 PM Two servers, one database
camperjohn's Avatar
Ultra Talker

Posts: 268
Location: San Diego
Trades: 0
Hi, what is the generally accepted method for handing a website database that is spread across two machines?

Let's say there is www.site.com and resources.site.com - both hold stuff for the site.

Let's sey both need to access the same MySQL database:

1) Do you put the database on one machine then get the second to query the first?

2) Do you have the database on both machines and then just mirror all new entries into the database (A tells B when something new arrives, and B tells A when something new arrives)

3) Or is there some server technology that is already in place that makes this transparent that a newb like me doesn't know about?

I am asking this question, so that when my site gets huge and I need to move to more than one machine, I am prepared.

JM

ps - is there a "scaling your website" tutorial I should read?
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
camperjohn is offline
Reply With Quote
View Public Profile Visit camperjohn's homepage!
 
 
Register now for full access!
Old 03-01-2005, 02:29 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
You can open up connections on remote machines, so it isn't a problem.

Code:
http://php.net/mysql_connect
resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )
Just change the usual 'localhost' to whatever server the database is hosted on.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 03-01-2005, 03:39 PM
camperjohn's Avatar
Ultra Talker

Posts: 268
Location: San Diego
Trades: 0
So then I can also do Lock table and Delete and Insert too right?

Ohhh, I am shivering!!! I like it...much easier than I thought.

But then another question. Before it gets on two machines, should I code as if it already is on the other machine?

Example, one machine, same database, should I change localhost to the same domain name, such that a scale up is automatic?

Is there an optimization penalty for connecting to "another machine" that is actually on the same machine, rather than "localhost".

Do you see what I mean?

JM
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE

Last edited by camperjohn; 03-01-2005 at 03:46 PM..
camperjohn is offline
Reply With Quote
View Public Profile Visit camperjohn's homepage!
 
Old 03-02-2005, 12:04 PM
Super Talker

Posts: 110
Trades: 1
This will depend on if you want the database to be updated from both servers. Choose your scenario first and then it will be easier to work out a solution.

Scenario 1 - Database updatable on both. This is where either server will be able to insert, update or delete records

Scenario 2 - Database updatable on only one master server. One server will be able to perform update functions whilst the other server is just in 'browsable' mode - i.e. can only read records.

Scenario 3 - Database updated manually and both servers to be browsable only. In otherwords, your database may be updated remotely by FTP or some other offline database connection, and the users of the database can only browse the data with no facility to insert, update, delete etc.

For S1 you are better off putting the database on the most reliable of the two servers. Continue to access the database from server A, and as the previous poster says, just change the localhost to the IP of the database server and access the data remotely. Note that some mysql installs have a security feature where the database can only be acccessed from the localhost machine. This is to stop cross site attacks on the server - all non remote users should turn this feature on, you will need to turn it off.

S2 is a better option for speed and gives you a bit of database redundancy. Server 1 will be able to update the server, Server 2 will be able to browse only. In this case it's best to synchronise the database so that any changes on server 1 are passed (delayed in time) to server 2. All browsers on server 2 will use the local database faster and if anything goes wrong with server 1 database you have a live backup (although some transactions will be missed depending on the time delay in updating).

S3 is similar to 2 where you just have a replicated database on the second server. Again, speed and redundancy are the benefits here but you will need to sync both databases.
Frank Rizzo is offline
Reply With Quote
View Public Profile Visit Frank Rizzo's homepage!
 
Old 03-02-2005, 01:28 PM
camperjohn's Avatar
Ultra Talker

Posts: 268
Location: San Diego
Trades: 0
Oh, I definately need the database to be updated and instered to from ALL machines....
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
camperjohn is offline
Reply With Quote
View Public Profile Visit camperjohn's homepage!
 
Old 03-02-2005, 02:51 PM
Super Talker

Posts: 110
Trades: 1
S1 is your answer then.

Put the database on the most reliable server and just remote connect to that server for your queries.
Frank Rizzo is offline
Reply With Quote
View Public Profile Visit Frank Rizzo's homepage!
 
Old 03-02-2005, 03:59 PM
camperjohn's Avatar
Ultra Talker

Posts: 268
Location: San Diego
Trades: 0
Then another question. I won't need the answer to this for quiet sometime.

"How does Yahoo do it with a billion members?" They can't just have one big server for the database queries can they? Or can they?...with a thousand other servers that hold the static data/images?
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
camperjohn is offline
Reply With Quote
View Public Profile Visit camperjohn's homepage!
 
Reply     « Reply to Two servers, one database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.66244 seconds with 12 queries