View Full Version : how would you put a database on it's own server?
twoodcc
Sep 8, 2009, 08:38 PM
i'm just curious to know how you would run a website with a database on it's own server? i read that macrumors does that, and i've read other big sites doing it as well.
and i'm sure some sites have the database on multiple servers. how would you do that as well?
thanks
angelwatt
Sep 8, 2009, 08:58 PM
Well, when you connect to the database, you simply put in the remote address.
<?php
$dbhost = 'http://remote.location';
$dbuser = 'user';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
?>
It's really no different than connection locally, just a different host name. In terms of multiple servers, you simply split your data into different databases, which are separated between them.
twoodcc
Sep 8, 2009, 10:20 PM
ok. i've never connected to a database remotely, only locally (like localhost or 127.0.0.1).
how would i connect remotely?
ChicoWeb
Sep 8, 2009, 10:34 PM
We've got two MySql servers running master master for a client. They also have 6 satellite web servers, but I'm guessing that may be overkill for your question.
There is no simple answer, but we use load balancers to even out the traffic, then a script to replicate everything instantaneously. Even writes go to one mysql server, odd writes go to the other mysql server, then they swap info within milliseconds. Therefore we have a redundant backup at all times along with doing backups every 2 hours, every night, once a week, and once a month. The duplicate mysql server evens out the load and acts as a real time backup.
Does that answer your question? You asked a big question at first, then your last comment seemed like you just wanted to connect to a database at a different ip so I don't know :)
twoodcc
Sep 8, 2009, 10:38 PM
We've got two MySql servers running master master for a client. They also have 6 satellite web servers, but I'm guessing that may be overkill for your question.
There is no simple answer, but we use load balancers to even out the traffic, then a script to replicate everything instantaneously. Even writes go to one mysql server, odd writes go to the other mysql server, then they swap info within milliseconds. Therefore we have a redundant backup at all times along with doing backups every 2 hours, every night, once a week, and once a month. The duplicate mysql server evens out the load and acts as a real time backup.
Does that answer your question? You asked a big question at first, then your last comment seemed like you just wanted to connect to a database at a different ip so I don't know :)
thank you for your reply! :) yes, that does help.
i have a few sites running off my own webserver, and i don't have a lot of traffic, but i do have priceless information. i might try and setup a backup mysql database on another machine if i can.
i do also want to know how to connect to a database with a different ip
joelypolly
Sep 8, 2009, 10:51 PM
http://connectionstrings.com/
this should explain how to do it with the connection string. Usually you just swap 127.0.0.1 or localhost to the IP or fully qualified name of the sever (I prefer IP address)
twoodcc
Sep 8, 2009, 11:12 PM
http://connectionstrings.com/
this should explain how to do it with the connection string. Usually you just swap 127.0.0.1 or localhost to the IP or fully qualified name of the sever (I prefer IP address)
thanks for the link :)
so it's that easy? just the ip address. does it only work on the same network? (just curious)
jeremy.king
Sep 15, 2009, 12:41 PM
does it only work on the same network? (just curious)
This would depend on firewall configuration - you can open ports (3306) to listen on an external interface, though I don't think most people do this because of security concerns.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.