CentOS: Can’t connect remotely to thesql server but I can ‘nc’ to it

centosinstallationmoodle;MySQL

I have two VMs, both running CentOS.

One is web server: 10.2.2.59
— in this server I put Moodle web application files.

One is DB server: 10.2.2.58
I installed MySQL and it is running nice, changed my.conf to comment #skipping-network and commented #bind-address.

I have config the firewall to accept port 3306

-A INPUT -s 10.3.2.59 -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

On (.59) I tried to nc -z 10.2.2.58 3306
and the output is

Connection to 10.2.2.58 3306 port [tcp/mysql] succeeded!

Also I tried to connect to mysql remotely from (.59) to (.58)
using mysql -u moodle_XXXX_ur -p -h 10.2.2.58

and it did connect and the mysql> prompt is showing.

I Grant 'moodle_XXXX_ur' all privileges to moodle_XXX_DB


The main problem is when I try to install moodle in (.59) with those parameters

Database host : 10.2.2.58
Database name : moodle_XXX_DB
Database user : moodle_XXXX_ur
Database password: XXXXXXXXXXXXX
Tables prefix: mdl_
Unix socket: true

I tried setting the Unix socket to false as well.

an error is showing saying that:

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

Warning: mysqli::mysqli(): (HY000/2002): Permission denied in /var/www/html/lib/dml/mysqli_native_moodle_database.php on line 76

line 76 looks like this:

$conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); // Connect without db

any help, or any way to trace the problem???

Best Answer

As stated here it could be because of selinux policy. Try to turn selinux off on both servers. Enable or Disable SELinux on CentOs