3
votes

I have moved my database to a different server and my applications files are still in the current server.

I have tried many ways to connect my database in the new server, But still it says

"Message: mysqli::real_connect() [mysqli.real-connect]: (HY000/2005): Unknown MySQL server host 'xxx.xxx.xxx.xxx:3306' (0)";

this is how my database.php is configured

'hostname' => 'xxx.xxx.xxx.xxx:3306',
'username' => '[my database user]',
'password' => '[my database password]',
'database' => '[my db]',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,

I appriciate if anyone can provide me a solution

2
try the hostname without :3306, port is a separate option and it should probably default to 3306. ellislab.com/codeigniter/user-guide/database/configuration.html - JimL
Hi, I have tried without port also. but still same results - user3818758
Are you able to connect to the database from the web server at all? Ie using the normal mysql client. - JimL
have you access to WHM? - Rejoanul Alam

2 Answers

3
votes

Commonly like this...

$db['default']['hostname'] = 'XXX.XX.XX.XXX'; //IP of server 
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_name';

Note:

Please allow your IP to be access for that database. Maybe that reasons why you can't connect with your remote database,

Hint:

  • In your CPanel, go to Remote Database Access Hosts and then set the host as % .. its means all IPs can be access to that database.
0
votes

Dude, you are remotely access database, so go to your new server's Remote MySQL option, and add write " % " ( without quotes ) in Add an Access Host textbox, [ to allow Host wildcard entry ] and click to Add Host button and then normally access your database configs ( no need to change your codes )