Mike Spider
Mike Spider

Reputation: 227

Connecting to external remote database

My website is in a remote host in Amazon AWS, I'm trying to connect to another database in GoDaDDy host. 2 websites sharing the same db.

I'm having the error :A Database Error Occurred.Unable to connect to your database server using the provided settings.

in amazon I have this in my database.php in config folder:

   $active_group = 'default';
   $active_record = TRUE;
   $db['default']['hostname'] = '192.186.236.98';
   $db['default']['username'] = 'username';
   $db['default']['password'] = 'mydbpwd';
   $db['default']['database'] = 'mydbname';
   $db['default']['dbdriver'] = 'mysql';
   $db['default']['dbprefix'] = '';
   $db['default']['pconnect'] = TRUE;
   $db['default']['db_debug'] = TRUE;
   $db['default']['cache_on'] = FALSE;
   $db['default']['cachedir'] = '';
   $db['default']['char_set'] = 'utf8';
   $db['default']['dbcollat'] = 'utf8_general_ci';
   $db['default']['swap_pre'] = '';
   $db['default']['autoinit'] = TRUE;
   $db['default']['stricton'] = FALSE;

Any help is welcome, Mike

Upvotes: 0

Views: 628

Answers (3)

stormdrain
stormdrain

Reputation: 7895

Make sure the Godaddy server has allowed access to the port needed. As of now, port 3306 is NOT open on this server, so the db connection will fail.

Nmap scan report for ip-192-186-236-98.ip.secureserver.net (192.186.236.98)
Host is up (0.049s latency).
PORT     STATE  SERVICE
3306/tcp closed mysql

Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds

Also add

$db['default']['port'] = 3306;

to the db config.


Update:

Since you have opened the port

root# nc -z -w1 192.186.236.98 3306
Connection to 192.186.236.98 port 3306 [tcp/mysql] succeeded!

still being unable to connect means you have the wrong username/password or database name set. If you can, check the mysql logs on the server.

Upvotes: 1

steve
steve

Reputation: 196

If you are trying to connect over SSL a mysql or mysqli database connection may fail with certain older versions of PHP and/or CI. I haven't had any SSL issues with the newer mysqli and PDO interfaces for versions at least PHP>=5.3.3 and CI>=2.1.3 but I do not know whether the older mysql interface can be made to work reliably over SSL.

Upvotes: 0

trizz
trizz

Reputation: 1447

Make sure the server you're connecting to, has port 3306 (or whatever port MySQL is running on, by default it is 3306) open in the firewall, and that the user you are using is allowed to create remote connections.

To be more secure, you can ask GoDaddy to allow only external connections to your DB from your Amazon IP address/range.

Upvotes: 0

Related Questions