diff --git a/includes/install.inc b/includes/install.inc
index e52c0ad..8a99ae6 100644
--- a/includes/install.inc
+++ b/includes/install.inc
@@ -623,7 +623,18 @@ function drupal_rewrite_settings($settings = array(), $prefix = '') {
           // Write new value to settings.php in the following format:
           //    $'setting' = 'value'; // 'comment'
           $setting = $settings[$variable[1]];
-          $buffer .= '$' . $variable[1] . " = " . var_export($setting['value'], TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");
+          // Add special handling for the $databases setting to improve readability and to
+          // match the format of the database settings documentation in settings.php.
+          if ($variable[1] == 'databases') {
+            foreach($setting['value'] as $db_first_key => $values) {
+              foreach($values as $db_second_key => $values) {
+                $buffer .= '$' . "databases['$db_first_key']['$db_second_key'] = " . var_export($values, TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");
+              }
+            }
+          }
+          else {
+            $buffer .= '$' . $variable[1] . " = " . var_export($setting['value'], TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");
+          }
           unset($settings[$variable[1]]);
         }
         else {
