diff --git a/core/lib/Drupal/Core/Command/DbDumpCommand.php b/core/lib/Drupal/Core/Command/DbDumpCommand.php
index a36366cc2eb99ecda37655479c2332a6a42d4699..ca01c4ec44e668bd717be302460135e1dd793f60 100644
--- a/core/lib/Drupal/Core/Command/DbDumpCommand.php
+++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
@@ -415,13 +415,17 @@ protected function getTemplate() {
 $connection = Database::getConnection();
 // Ensure any tables with a serial column with a value of 0 are created as
 // expected.
-$sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField();
-$connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
+if ($connection->databaseType() === 'mysql') {
+  $sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField();
+  $connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
+}
 
 {{TABLES}}
 
 // Reset the SQL mode.
-$connection->query("SET sql_mode = '$sql_mode'");
+if ($connection->databaseType() === 'mysql') {
+  $connection->query("SET sql_mode = '$sql_mode'");
+}
 ENDOFSCRIPT;
     return $script;
   }