diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php
index d671758..358fa71 100644
--- a/core/lib/Drupal/Core/Database/Connection.php
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -1273,8 +1273,9 @@ public function quote($string, $parameter_type = \PDO::PARAM_STR) {
    */
   public function serialize() {
     $connection = clone $this;
-    // Don't serialize the PDO connection and other lazy-instantiated members.
-    unset($connection->connection, $connection->schema, $connection->driverClasses);
+    // Don't serialize the PDO connection as well as everything else which
+    // depends on settings.php.
+    unset($connection->connection, $connection->connectionOptions, $connection->schema, $connection->prefixes, $connection->prefixReplace, $connection->driverClasses);
     return serialize(get_object_vars($connection));
   }
 
@@ -1286,6 +1287,8 @@ public function unserialize($serialized) {
     foreach ($data as $key => $value) {
       $this->{$key} = $value;
     }
+    $this->connectionOptions = Database::getConnectionInfo($this->key)[$this->target];
+
     // Re-establish the PDO connection using the original options.
     $this->connection = static::open($this->connectionOptions);
 
@@ -1293,6 +1296,8 @@ public function unserialize($serialized) {
     if (!empty($this->statementClass)) {
       $this->connection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
     }
+
+    $this->setPrefix(isset($this->connectionOptions['prefix']) ? $this->connectionOptions['prefix'] : '');
   }
 
 }
diff --git a/core/modules/system/src/Tests/Database/ConnectionUnitTest.php b/core/modules/system/src/Tests/Database/ConnectionUnitTest.php
index 0d7e506..754aa85 100644
--- a/core/modules/system/src/Tests/Database/ConnectionUnitTest.php
+++ b/core/modules/system/src/Tests/Database/ConnectionUnitTest.php
@@ -235,6 +235,11 @@ public function testConnectionSerialization() {
       $this->fail('The database connection cannot be serialized.');
     }
 
+    $not_serialized_properties = ['connection', 'connectionOptions', 'schema', 'prefixes', 'prefixReplace', 'driverClasses'];
+    foreach ($not_serialized_properties as $property) {
+      $this->assertIdentical(FALSE, strpos($serialized, $property));
+    }
+
     // Ensure that all properties on the unserialized object are the same.
     $db_reflection = new \ReflectionObject($db);
     $unserialized_reflection = new \ReflectionObject($unserialized);
