There are times when you have your project deployed on a server(lets call it Server PR) and MySQL Database on another system(say Server MD). The reason for having this segregation could be performance benefit or something else. Today I wanted to do the same in one of my Drupal project. First I tried by simply changing the host and port number in my settings.php file. For those who are not familiar with Drupal, settings.php is a file where you save your Database and Server related configurations.

This is what I did:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'DATABASE_NAME',
      'username' => 'root',
      'password' => 'PASSWORD', 
      'host' => '192.168.1.5',   //IP Address
      'port' => '3306',  //Port Number
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

1. I changed the host from localhost to 192.168.1.5 (the IP address of Server MD, the system where database resides).

2. Though its optional, I changed the port to 3306. If you leave it as empty, 3306 is the value taken by default.

The changes I made here were correct but the site was not loading when I visited http://my-website.com. After a while I figured out that the system where MySQL database resides, will have to allow remote access to it. So, here comes the main part of the article: How to allow Server PR to access the database in Server MD?

#mysql

Remote Access to MySQL Server
1.10 GEEK