0

OK I have researched every step and done as much as I could and still get the following error:

Error!: SQLSTATE[HY000] [2002] No connection could be made because 
the target machine actively refused it.

(BTW this solution, PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused, does not relate, my problem refers to a connection to a remote mysql server, not a virtual machine, and changing to port 8888 or port 8889 has no effect on the message..)

Here is what I did:

  1. I have created a remote connection in mysql: GRANT ALL PRIVILEGES ON fin_sample.* to fin_test@'%' identified by '****';

  2. I have changed bind-address = 0.0.0.0 in /etc/mysql/mysql.conf.d/mysql.cnf

  3. Confirmed I stopped and restarted mysql.

At this point the server should be accepting remote connections. Here is my code:

    try {
        $user = 'fin_test';
        $pass = '****';
        // Note "recommended" space after colon..
        $dbh = new PDO('mysql: host=67.205.123.123;dbname=fin_test', $user, $pass);
        foreach($dbh->query('SELECT * FROM fin_test.progview_sample') as $row) {
            print_r($row);
        }
        $dbh = null;
    } catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br/>";
        die();
    }

I am wondering how I debug this, or what is going wrong? I get the same response regardless of what input I use.

Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
  • https://stackoverflow.com/questions/29395452/php-connection-failed-sqlstatehy000-2002-connection-refused – Mubashar Iqbal Oct 21 '17 at 22:22
  • 1
    Eliminate that "recommended" space, remove ".com" from connection host, remove all fetching codes (for now) and try again. Anything? –  Oct 21 '17 at 22:51
  • See enapupe's [answer](https://stackoverflow.com/questions/21987746/mysql-connect-no-connection-could-be-made-because-the-target-machine-actively). –  Oct 21 '17 at 22:57
  • removing the space and the ".com" (switching to an IP address, which I had at one point as I tried a gazillion permutations) did work @aendeerei - I do not know what you mean by "fetching code" - I can say that the only param I seem to really need is hostname=IP_address. – Oliver Williams Oct 21 '17 at 23:00
  • Yes, as in the "take the car to the mechanic and it works" - I've edited my post. – Oliver Williams Oct 21 '17 at 23:04
  • check the firewall settings on the target server? – Karman Kertesz Oct 21 '17 at 23:08

1 Answers1

0

Solution:

I was able to solve the below by doing the following:

  • removing all parameters except for hostname=..
  • in addition I had a stupid error of .com after the IP address. Warning!! PDO is not going to tell you you are connecting to the wrong place!
  • making hostname be an IP address

I do feel it's important to understand that you must modify the bind-address and restart mysql for the database you want to call.

Community
  • 1
  • 1
Oliver Williams
  • 5,966
  • 7
  • 36
  • 78