DonX DonX - 5 months ago 118
SQL Question

Codeigniter SSH Connection to remote MySQL DB

I am trying to connect to our live Database remotely using Codeigniter. However I'm getting an error:


Message: mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'10.54.9.20' (using password: YES)


Database.php config file:

$db['default'] = array(
'dsn' => '',
'hostname' => 'xx.xx.xxx.xxx',
'username' => 'username',
'password' => 'password',
'database' => 'database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE, //tried changing this to TRUE
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);


I have no issue using the DB in my localhost however getting errors when using remote config.

Need help. Thanks guys!

Answer

Login from localhost and run the following commands:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'YOUR_PASSWORD' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Now try to gain access remotely.

Comments