Question

Problem connect php 7.3 and MYSQL 8

Hi, I can’t connect php 7.3 with cluster database mysql 8 I did tests with previous versions of php 5.7, 7.1 and 7.2 also

User native

# user, plugin, host
'doadmin', 'mysql_native_password', '%'

PHP

<?php
ini_set('display_errors', 1);
$servername = "db-mysql-xxxxx-do-user-xxxxxx.db.ondigitalocean.com";
$username = "doadmin";
$password = "password";

echo "$username";
// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

Error

Warning: mysqli::__construct(): (HY000/2003): Can't connect to MySQL server on 'db-mysql-xxxxx-do-user-xxxxxx.db.ondigitalocean.com' (110) in /home/151548/public_html/prueba.php on line 9
Connection failed: Can't connect to MySQL server on 'db-mysql-xxxxx-do-user-xxxxxx.db.ondigitalocean.com' (110)

....

I read several DigitalOcean tutorials but none has helped me, what can I do?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, I had already tried but not yet connected, when I write the port in the code it disconnects me immediately and sends me the error message Unknown MySQL server host

Without port, the page tries to communicate with the mysql server, approximately 1 minute later it shows the error Can’t connect to MySQL server

Port Warning: mysqli::__construct(): (HY000/2005): Unknown MySQL server host ‘db-mysql-xxxx-do-user-2457458-0.db.ondigitalocean.com:25060’ (0) in /home/xxxx/public_html/prueba.php on line 11 Connection failed: Unknown MySQL server host ‘db-mysql-xxxx-do-user-2457458-0.db.ondigitalocean.com:25060’ (0)

no port

Warning: mysqli::__construct(): (HY000/2003): Can’t connect to MySQL server on ‘db-mysql-xxxx-do-user-2457458-0.db.ondigitalocean.com’ (110) in /home/xxxx/public_html/prueba.php on line 11 Connection failed: Can’t connect to MySQL server on ‘db-mysql-xxxx-do-user-2457458-0.db.ondigitalocean.com’ (110)

Any other advice? I have followed all questions of digitalocean, I’ve been trying to connect for several days

Hello,

As the Managed MySQL databases do not use the standard 3306 port, you need to make sure that you specify the Managed database cluster port in your connection string. After that this should work as normal.

I think that with mysqli the syntax should be something like this:

$conn = new mysqli(host, username, password, dbname, port);

Hope that this helps! Regards, Bobby