Report this

What is the reason for this report?

Problem connect php 7.3 and MYSQL 8

Posted on January 15, 2020

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?



This textbox defaults to using Markdown to format your 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.

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

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

I’m using this PHP and works. Hope it’s help.

<?php $host =“”; //host server $user =“”; //user login $pass =“”; //pass login $db =“”; //db name $port = “”; //port DB $conn = mysqli_connect($host, $user, $pass, $db, $port) or die (“connection failed”); if ($conn->connect_error) { die('connection failed: '. $con->connect_error); } ?>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.