1

This question already has an answer here:

I have an API i want to deploy to OpenShift, everything works locally, but when trying to use it online i get some problems. When trying to connect to the database, using PDO, i get this error:

Failed to connect to the database: SQLSTATE[HY000] [2002] Connection refused

i have the database set up correctly, and i have the correct details for the connection (im pretty sure). heres some code:

$username = "myuser"; 
$password = "lmnop"; 
$host = "127.0.0.1"; 
$dbname = "loginapi"; 
$port = "3306";

$db = new PDO("mysql:host={$host};port={$port};dbname={$dbname};charset=utf8", $username, $password, $options);

what could be wrong that OpenShift is not allowing the connection? considering that this works on my local machine?

thanks!

marked as duplicate by Iain, HBruijn Sep 28 '15 at 16:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Try each of these steps, clear cache, refresh and check

  1. From $host = "127.0.0.1"; change to $host = "localhost";

  2. Check whether the default port is 3306 or anything else. Check the process name and port

    netstat -tln

  3. Enable skip-networking (comment out # ) in my.cnf

  4. Have a look in /etc/hosts as well to ensure everything is fine there

  5. Also --bind-address if set to 127.0.0.1, the server accepts connections only on that address

  • Explanation is that mysql uses a unix socket for communication when using localhost but tries a network connection with the IP address. Often the mysql daemon doesn't listen on the network (via the skip-networking directive) for security reasons. – wurtel May 8 '15 at 14:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.