By iltgbw
I am getting the following error after I first deployed my app: Database connection failed: Connection timed out (2002)
Thank you in advance!
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!
Hi,
if your mysqld is running on the same box as the rest of the stack then you should definitely be using a UNIX socket to connect to mysql.
What does your mysql connection stanza look like in the code?
Yes, it is running on the same box.
defined(‘DB_SERVER’) ? null : define(“DB_SERVER”, “<my_ip_address>”); defined(‘DB_USER’) ? null : define(“DB_USER”, “<db_username>”); defined(‘DB_PASS’) ? null : define(“DB_PASS”, “<db_password>”); defined(‘DB_NAME’) ? null : define(“DB_NAME”, “<db_name”);
private $connection;
function __construct() { $this->open_connection(); }
public function open_connection() { $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME); if(mysqli_connect_errno()) { die(“Database connection failed: " . mysqli_connect_error() . " (” . mysqli_connect_errno() . “)” ); } }
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.