access remote Digitaocean databases PHP - Mysql

September 26, 2019 154 views
Databases DigitalOcean

I want to use the new DigitalOcean MySQL Managed Databases with my PHP application but I’m getting this error here:

https://distanciauss.com/test.php

Connect Error (2003) Can’t connect to MySQL server on ‘db-mysql-aldodiego-2019-do-user-6529643-0.db.ondigitalocean.com’ (110)

already change the database password type to: mysqlnativepassword

I still have the same error can someone help me connect?

I am using this code

<?php
$mysqli = new mysqli('<host>', '<user>', '<password>', '<database>');

/*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}

/*
 * Use this instead of $connect_error if you need to ensure
 * compatibility with PHP versions prior to 5.2.9 and 5.3.0.
 */
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
?>
2 Answers

Hello,

I would recommend checking the following:

  • Make sure that you have specified the 25060 MySQL port in your connection string, it is not the default one so you need to specify it explicitly

  • Make sure that you have added your Droplet’s IP under the trusted sources for your Managed database

  • Make sure that the outgoing TCP traffic for port 25060 is allowed on your droplet

Hope that this helps!
Regards,
Bobby

  • Everything is already added, can you help me with that please

    • It sounds like that the outgoing TCP traffic for port 25060 might not be open on your droplet. To test that what you could do is:

      • SSH to your droplet

      • Then run:

      telnet db-mysql-YOUR_DB_CLUSTER_NAME.db.ondigitalocean.com 25060
      

      That way you would be able to test the connection.

      If this fails, I would suggest checking your firewall status:

      sudo ufw status
      

      Let me know how it goes!

Have another answer? Share your knowledge.