Balakumar B
Balakumar B

Reputation: 790

Query a database on a different Server

For the sake of anonymity, let's pretend my website is called, www.example.com.

I need to access another server with an IP address of 46.258.254.21 from www.example.com.

The following config works fine:

define ( 'DB_HOST', 'localhost' );
define ( 'DB_USER', 'siteroot' );
define ( 'DB_PASSWORD', 'sitepwd' );
define ( 'DB_DB', 'my_db' );

The following config did not work:

define ( 'DB_HOST', '46.258.254.21' );
define ( 'DB_USER', 'ifd' );
define ( 'DB_PASSWORD', 'pwd' );
define ( 'DB_DB', 'my_db1' );

It threw a Could not connect to MySQL server was not found on this server. exception.

What might be preventing me from connecting to 46.258.254.21?

Upvotes: 1

Views: 78

Answers (1)

GrabzIt
GrabzIt

Reputation: 41

Things to check:

  • The port number of your MySQL instance can be found in the mysql config file: my.cnf. It's usually 3306.
  • If you are accessing your database server from a remote machine you will need to open this port on your firewall. Otherwise it will be blocked. You will probably want to restrict the port to the IP address of your web server as described in this answer.

Upvotes: 1

Related Questions