diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
index 7be16b3..c15d59a 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
@@ -161,9 +161,6 @@ public function databaseType() {
    * @throws \Drupal\Core\Database\DatabaseNotFoundException
    */
   public function createDatabase($database) {
-    // Escape the database name.
-    $database = Database::getConnection()->escapeDatabase($database);
-
     try {
       // Create the database and set it as active.
       $this->connection->exec("CREATE DATABASE $database");
diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
index 5a1f1ae..899a4bc 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
@@ -62,9 +62,15 @@ protected function connect() {
         Database::addConnectionInfo('default', 'default', $connection_info['default']);
 
         try {
-          // Now, attempt the connection again; if it's successful, attempt to
-          // create the database.
-          Database::getConnection()->createDatabase($database);
+          // Now attempt the connection again. If successful, check if the given
+          // database name is valid for creation.
+          $create_database = Database::getConnection()->escapeDatabase($database);
+          if ($create_database != $database) {
+            $this->fail(t("Database %database not found. The database also can't be created because in the name only alphanumeric characters and underscores are allowed.", array('%database' => $database)));
+            return FALSE;
+          }
+          // If it is, attempt to create the database.
+          Database::getConnection()->createDatabase($create_database);
         }
         catch (DatabaseNotFoundException $e) {
           // Still no dice; probably a permission issue. Raise the error to the
diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
index 68e9c98..19d48c4 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
@@ -199,9 +199,6 @@ public function databaseType() {
    * @throws \Drupal\Core\Database\DatabaseNotFoundException
    */
   public function createDatabase($database) {
-    // Escape the database name.
-    $database = Database::getConnection()->escapeDatabase($database);
-
     // If the PECL intl extension is installed, use it to determine the proper
     // locale.  Otherwise, fall back to en_US.
     if (class_exists('Locale')) {
diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
index 06cc2b0..abe0bf7 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
@@ -79,9 +79,15 @@ protected function connect() {
         Database::addConnectionInfo('default', 'default', $connection_info['default']);
 
         try {
-          // Now, attempt the connection again; if it's successful, attempt to
-          // create the database.
-          Database::getConnection()->createDatabase($database);
+          // Now attempt the connection again. If successful, check if the given
+          // database name is valid for creation.
+          $create_database = Database::getConnection()->escapeDatabase($database);
+          if ($create_database != $database) {
+            $this->fail(st("Database %database not found. The database also can't be created because in the name only alphanumeric characters and underscores are allowed.", array('%database' => $database)));
+            return FALSE;
+          }
+          // If it is, attempt to create the database.
+          Database::getConnection()->createDatabase($create_database);
           Database::closeConnection();
 
           // Now, restore the database config.
