Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 27915)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -549,6 +549,15 @@
 	private $use_mysqli = false;
 
 	/**
+	 * Whether we've managed to successfully connect at some point
+	 *
+	 * @since 3.9.0
+	 * @access private
+	 * @var bool
+	 */
+	private $has_connected = false;
+
+	/**
 	 * Connects to the database server and selects a database
 	 *
 	 * PHP5 style constructor for compatibility with PHP5. Does
@@ -1336,6 +1345,14 @@
 
 			if ( $this->dbh->connect_errno ) {
 				$this->dbh = null;
+
+				// Something went wrong with the mysqli connect.
+				// If this is the first connection attempt, we should try
+				// to fallback to ext/mysql.
+				if ( ! $this->has_connected ) {
+					$this->use_mysqli = false;
+					$this->db_connect();
+				}
 			}
 		} else {
 			if ( WP_DEBUG ) {
@@ -1367,6 +1384,7 @@
 
 			return false;
 		} else if ( $this->dbh ) {
+			$this->has_connected = true;
 			$this->set_charset( $this->dbh );
 			$this->set_sql_mode();
 			$this->ready = true;
