I am getting the following error after I first deployed my app: Database connection failed: Connection timed out (2002)

Thank you in advance!

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.

2 answers


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(‘DBSERVER’) ? null : define(“DBSERVER”, “<my_ip_address>”);
defined('DBUSER’) ? null : define(“DBUSER”, “<db_username>”);
defined('DBPASS’) ? null : define(“DBPASS”, “<db_password>”);
defined('DBNAME’) ? null : define(“DBNAME”, “<db_name”);

private $connection;

function _construct() {

public function openconnection() {
$this->connection = mysqli
if(mysqliconnecterrno()) {
die(“Database connection failed: ” .
mysqliconnecterror() .
“ (” . mysqliconnecterrno() . “)”

Submit an Answer