1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can I host wordpress database in an other server?

Discussion in 'Databases' started by hungvn9, Jan 12, 2014.

  1. #1
    Hi,

    I wonder if we can host wordpress database (mysql) in an other server which is not the server storing the content (source code, uploads files, plugins, theme...)
    Will that make any performance and security improvement? Is there any service specialized in hosting only database?

    Thanks,
     
    Last edited: Jan 12, 2014
    hungvn9, Jan 12, 2014 IP
  2. suvidha.writer

    suvidha.writer Active Member

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Yes, as long as the MySQL server allows the database to be accessed by external servers.
    When you set up WP, instead of "localhost", you'll put in the SQL server.
     
    suvidha.writer, Jan 12, 2014 IP
  3. hungvn9

    hungvn9 Member

    Messages:
    179
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #3
    Thanks, what if I already installed wordpress before and want to move the database?
    There are still some concerns that I need your help
     
    hungvn9, Jan 12, 2014 IP
  4. sundaybrew

    sundaybrew Numerati

    Messages:
    7,294
    Likes Received:
    1,260
    Best Answers:
    0
    Trophy Points:
    560
    #4
    Yes, you can export the current database, then you will create a database on another server,

    then instead of "localhost" (in the config.php ) you will put the IP address of the server and then the config.php will connect :)
     
    sundaybrew, Jan 12, 2014 IP
  5. khodem

    khodem Well-Known Member

    Messages:
    206
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    120
    #5
    well this is not good idea unless your Wordpress source file and your database are in the same network... what I mean is if you host your database in different network and your source in different network there would be a lot of latency... as when someone access your site the source files have to access database across internet to put out the information and sometimes access this through internet is bad bad idea
     
    khodem, Jan 24, 2014 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    You won't get any performance boosts from this, unless you're having a LOT of traffic, separate hosting/caching/sql-servers, and running each on a separate server within a fiber-cable-setup or at least GB-local network - there is NO real point in running this on separate servers, unless you're running this on a poorly configured shared-hosting server - then you might get a slight improvement by running the SQL on a separate server, but yet again, only if it's on a local node. Going through the Internet for this is NOT recommended. Also, remember that if you go through the Internet, this will be pulled from any traffic-charges (bandwidth) you have.
     
    PoPSiCLe, Jan 31, 2014 IP
  7. HalfDedi

    HalfDedi Greenhorn

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    8
    #7
    this only good if both web server and database server are in the same network or better in a private LAN configuration as it will have little ping time and secure (data are not transferred via internet connection)
     
    HalfDedi, Jan 31, 2014 IP
  8. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #8
    Well in case you got plenty of visitors it's worth using a dedicated/vps just for your sql db, and separate http from db. And even more in future it will be better to use clusters for http and db.
     
    hip_hop_x, Feb 4, 2014 IP
  9. phptechie

    phptechie Well-Known Member

    Messages:
    885
    Likes Received:
    10
    Best Answers:
    2
    Trophy Points:
    165
    #9
    As said by others , its not advisable to have them separately.
    One other reason is that , if the server that has the database fails or shuts down , then the website files will not be able to access the database & so your site will not display to the end user.
    Also bandwidth will be different for these 2 servers , which will also add pain when you have more visitors / traffic at any point in time.

    Last but not least , when you upgrade php versions & mysql versions , you have to do it on both the servers , which will be time consuming & cost you more money.

    So the best option would be to move onto a dedicated server hosting both the source files & database on the same server , this will be bit easier for you to update/manage the server in future.

    Hope this helps :)
     
    phptechie, Mar 3, 2014 IP
  10. Brands-and-Jingles

    Brands-and-Jingles Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #10
    
    
    // wp-config.php
    
    define ( 'DB_NAME', 'yourdbname' );
    define ( 'DB_USER', 'yourusername' );
    define ( 'DB_PASSWORD', 'yourpassword' );
    define ( 'DB_HOST', '111.222.0.1' ); // IP address of the server where MySQL is running 
    
    // make sure MySQL server will listen to the request from your WP server IP !
    
    
    Code (markup):
     
    Brands-and-Jingles, Mar 20, 2014 IP
  11. buythiscomputer

    buythiscomputer Member

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #11

    hello, so it's always better to host database + files on the same server ?

    Thanks.
     
    buythiscomputer, May 14, 2017 IP
  12. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #12
    No. Not necessarily. Same NETWORK. If you have a GB-connection between the file-server and the db-server, you're pretty good. If you have a 10GB connection, you're golden. If they're on different subnets, or different locations, or even worse, have no dedicated line between them, you're gonna have latency issues, packet drops and other problems.
     
    PoPSiCLe, May 15, 2017 IP
  13. webhost.uk.net

    webhost.uk.net Well-Known Member

    Messages:
    296
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    128
    #13
    Right, infact a separate mysql and webserver will improve speed and performance ,we have done such clustered solutions for few of our customers.
     
    webhost.uk.net, May 16, 2017 IP
  14. buythiscomputer

    buythiscomputer Member

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #14
    can you explain me why separate mysql and files server can improve ? if you have only 1 server but very powerful and with lots of RAM, wouldn't it be better ?
     
    buythiscomputer, May 16, 2017 IP
  15. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #15
    Depending on what you need, and how much load you put on both the webserver and/or DB-server, there is just so much you can do with one server, before the cost is becoming prohibitive. By dividing it up, you have separate servers doing the work only for what they host. 20000 user on your webserver? Not that big a problem. 20000 users using the database? Not a big problem. Having 40000 users on the same server, using both the webserver and the db-server might be harder - also, take note that these numbers are just arbitrarty numbers used to prove the point. Depending on your specific server-setup, the number might be lower, or it might be higher.
     
    PoPSiCLe, May 16, 2017 IP
  16. webhost.uk.net

    webhost.uk.net Well-Known Member

    Messages:
    296
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    128
    #16
    If you keep webserver and mysql access separate , may server process will be divide , and CPU usage of the server will also be divide in this case. A single server when handles all the process it will affect the performance.
     
    webhost.uk.net, May 17, 2017 IP
  17. Paul Mahony

    Paul Mahony Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #17
    Quite simply everything depends on the host's capability to establish a remote database connection. If it does, use the database's location IP address as the hostname.
     
    Paul Mahony, Sep 5, 2017 IP
  18. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #18
     
    Imran, Sep 21, 2017 IP
  19. Cameron Fillers

    Cameron Fillers Member

    Messages:
    33
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #19
    The main reason to split up a web server and a database server is dedicated resources. Generally with php, you have a wide variety of settings that allow the setting to use a range of resources. With mysql, your my.cnf file allows you to set various configuration settings, and depending on your max "connections" settings, will use a range of RAM. By separating the two, you can set the database server to have a dedicated amount of RAM, CPU, and allow the web server to have its own set of resources. By having them on the same server, you increase the chances of one service monopolizing the resources and starving the other, which can lead to hangups or swapping since the servers are trying to load additional ram, and cannot find any. In bad scenarios, the server may start killing processes to free up resources (can sometimes be the mysql daemon). If you are running small wordpress or drupal website, then this not a big issue, and you should keep it on the same server.

    If you are running a beefy site, you may want to split up your configuration so that mysql is running on a ssd server, and your web server is running separately, with more space, on a hdd server. As most resources will be stored in ram, the gain in having your web service on ssd is not much, compared to mysql. And mysql will get a boost from the additional read/write that SSD affords, while keeping costs lower.

    Regardless, the OP asked if you could, and of course you can. My recommendation is to dump your database

    mysqldump [database] > [database].dump
    transfer it to the external mysql server, import it
    mysql [database] < [database].dump

    and then make sure that you create the mysql user on the external database, and set the ip/domain of the web server for host. You do not want to allow % (anyone) access. If you are familiar with it, lock down port 3306 to the web server, and then on the web server, run a test to verify that you can connect to the external database server
    mysql -u[user] -p -h[external database domain/ip] [database]

    I recommend doing this as you can spend quite a bit of time debugging why things are not working, when it may just simply be an invalid user configuration on the external database.

    If you are using cPanel, there is an option for external databases, so that you can allow access to a specific external domain. If you run into issues, open up a ticket with your hosting provider, as they may block external access to port 3306 (mysql) which could cause you a lot of time and frustration to debug.
     
    Cameron Fillers, Jun 18, 2018 IP