H.joshi
H.joshi

Reputation: 51

Connect to mysql database with local Ip address - Codeigniter

I want to connect to database with ip address instead of local host, but when I write IP Address (another PC in LAN), it shows me error of permission denied.My connection array is as follows:

$db['default']['hostname'] = '192.168.1.122';
$db['default']['username'] = 'root';
$db['default']['password'] = '123456';
$db['default']['database'] = 'test_db';
$db['default']['dbdriver'] = 'mysqli';

result is:

Message: mysqli::real_connect(): (HY000/2002): Permission denied Filename: mysqli/mysqli_driver.php

I am using CentOS 7 and tried connection with telnet and it is working fine there.

Upvotes: 0

Views: 2104

Answers (2)

JoshOiknine
JoshOiknine

Reputation: 470

I had the same issue and found the solution to be that Apache was not set to allow remote connections.

You can run this to check:

getsebool -a | grep httpd_can_network

I ran the following to fix the issue:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1

Source:

Upvotes: 0

jeprubio
jeprubio

Reputation: 18002

Probably you haven't the permission to log as root from a host different from localhost. You can find info here.

You can grant permissions to root this way:

GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'mysql root password';

Upvotes: 1

Related Questions