how would you put a database on it's own server?

Discussion in 'Web Design and Development' started by twoodcc, Sep 8, 2009.

  1. twoodcc macrumors P6

    twoodcc

    Joined:
    Feb 3, 2005
    Location:
    Right side of wrong
    #1
    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
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Well, when you connect to the database, you simply put in the remote address.
    PHP:
    <?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.
     
  3. twoodcc thread starter macrumors P6

    twoodcc

    Joined:
    Feb 3, 2005
    Location:
    Right side of wrong
    #3
    ok. i've never connected to a database remotely, only locally (like localhost or 127.0.0.1).

    how would i connect remotely?
     
  4. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
    #4
    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 :)
     
  5. twoodcc thread starter macrumors P6

    twoodcc

    Joined:
    Feb 3, 2005
    Location:
    Right side of wrong
    #5
    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
     
  6. joelypolly macrumors 6502

    Joined:
    Sep 14, 2003
    Location:
    Melbourne & Shanghai
    #6
    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)
     
  7. twoodcc thread starter macrumors P6

    twoodcc

    Joined:
    Feb 3, 2005
    Location:
    Right side of wrong
    #7
    thanks for the link :)

    so it's that easy? just the ip address. does it only work on the same network? (just curious)
     
  8. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #8
    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.
     

Share This Page