Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 39215)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -3039,10 +3039,9 @@
 
 		// SHOW TABLE STATUS and SHOW TABLES
 		if ( preg_match( '/^\s*(?:'
-				. 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
-				. '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
-				. ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
-			return str_replace( '`', '', $maybe[1] );
+				. 'SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES).+(?:LIKE\s+|WHERE\s+Name(?:\s*=\s*|\s+LIKE\s+))'
+				. ')\W((?:\\\\_|[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
+			return str_replace( array( '`', '\\_' ), array( '', '_' ), $maybe[1] );
 		}
 
 		// Big pattern for the rest of the table-related queries.
Index: tests/phpunit/tests/db.php
===================================================================
--- tests/phpunit/tests/db.php	(revision 39215)
+++ tests/phpunit/tests/db.php	(working copy)
@@ -671,6 +671,44 @@
 	}
 
 	/**
+	 * @ticket 38751
+	 */
+	function data_get_escaped_table_from_show_query() {
+		$table = 'wp_123_foo';
+		$escaped_table = 'wp\_123\_foo';
+
+		$queries = array(
+			"SHOW TABLES LIKE '$escaped_table'",
+			"SHOW TABLES WHERE Name LIKE '$escaped_table'",
+
+			"SHOW FULL TABLES LIKE '$escaped_table'",
+			"SHOW FULL TABLES WHERE Name LIKE '$escaped_table'",
+
+			"SHOW TABLE STATUS LIKE '$escaped_table'",
+			"SHOW TABLE STATUS WHERE Name LIKE '$escaped_table'",
+		);
+
+		$data = array();
+
+		foreach ( $queries as $query ) {
+			$data[] = array( $query, $table );
+
+			// Test for double quotes, too.
+			$data[] = array( str_replace( "'", '"', $query ), $table );
+		}
+
+		return $data;
+	}
+
+	/**
+	 * @dataProvider data_get_escaped_table_from_show_query
+	 * @ticket 38751
+	 */
+	function test_get_escaped_table_from_show_query( $query, $table ) {
+		$this->assertEquals( $table, self::$_wpdb->get_table_from_query( $query ) );
+	}
+
+	/**
 	 * @ticket 21212
 	 */
 	function data_process_field_formats() {
