Question

PHP Fatal error: Uncaught mysqli_sql_exception: Connection timed out

I’m connecting to my droplet fine on localhost, which proves that the IP, port, user and pw are correct, but when I load the same php code to a server that is supposed to connect to my DO database, I get:

PHP Fatal error: Uncaught mysqli_sql_exception: Connection timed out

Can anyone help me? this article doesn’t help becasue I can’t see the Control Panel (I have CLI) https://docs.digitalocean.com/products/databases/mysql/how-to/secure/#firewalls


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
December 16, 2024

Hi there,

If you are using a Managed MySQL database cluster there are a few things that you need to make sure that you have in place:

  • The Managed MySQL clusters do not use the default MySQL port, so you need to make sure that you are using 25060 as your port in your connection string
  • If you have enabled the trusted sources for your MySQL cluster, then you need to make sure that you also add your Droplet’s IP address to the allowed list so that the Droplet can connect to the MySQL cluster
  • If you have a firewall on your Droplet like UFW or a managed cloud firewall, make sure that you open port 25060 for outgoing TCP connections so that the Droplet can connect to the MySQL cluster

Let me know how it goes!

- Bobby

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.