Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 29354)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -1345,6 +1345,8 @@
 
 		$this->is_mysql = true;
 
+		$mysqli_connected = false;
+
 		/*
 		 * Deprecated in 3.9+ when using MySQLi. No equivalent
 		 * $new_link parameter exists for mysqli_* functions.
@@ -1376,7 +1378,7 @@
 			}
 
 			if ( WP_DEBUG ) {
-				mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
+				$mysqli_connected = mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
 			} else {
 				@mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
 			}
@@ -1407,6 +1409,19 @@
 		} else {
 			if ( WP_DEBUG ) {
 				$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
+
+				if ( is_resource( $this->dbh ) && $mysqli_connected === false ) {
+					$mysql_sock_path = ini_get( 'mysql.default_socket' );
+					$mysqli_sock_path = ini_get( 'mysqli.default_socket' );
+
+					$mysql_connection_error = "mysqli_real_connect() failed and mysql_real_connect() succeeded. Check your mysqli configuration.";
+
+					if ( $this->show_errors && $mysql_sock_path && $mysqli_sock_path && ( $mysql_sock_path != $mysqli_sock_path ) ) {
+						$mysql_connection_error .= " The mysql socket is $mysql_sock_path. The mysqli socket is $mysqli_sock_path. They should be the same.";
+					}
+
+					trigger_error($mysql_connection_error, E_USER_WARNING);
+				}
 			} else {
 				$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
 			}
