diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index daf4668..ab67e45 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -940,7 +940,10 @@ public function schema() {
    */
   public function escapeDatabase($database) {
     if (!isset($this->escapedNames[$database])) {
-      $this->escapedNames[$database] = preg_replace('/[^A-Za-z0-9_.]+/', '', $database);
+      $this->escapedNames[$database] = preg_replace('/[^A-Za-z0-9_.-]+/', '', $database);
+      if (strpos($this->escapedNames[$database], '-') !== FALSE) {
+        $this->escapedNames[$database] = '`' . $this->escapedNames[$database] . '`';
+      }
     }
     return $this->escapedNames[$database];
   }
@@ -960,7 +963,17 @@ public function escapeDatabase($database) {
    */
   public function escapeTable($table) {
     if (!isset($this->escapedNames[$table])) {
-      $this->escapedNames[$table] = preg_replace('/[^A-Za-z0-9_.]+/', '', $table);
+      if (strpos($this->escapedNames[$table], '.') !== FALSE) {
+        list($database, $this->escapedNames[$table]) = explode('.', $this->escapedNames[$table]);
+
+        $database = $this->escapeDatabase($database);
+      }
+
+      $this->escapedNames[$table] = preg_replace('/[^A-Za-z0-9_.]+/', '', $this->escapedNames[$table]);
+
+      if (isset($database)) {
+        $this->escapedNames[$table] = $database . '.' . $this->escapedNames[$table];
+      }
     }
     return $this->escapedNames[$table];
   }
