4

Is there a quick, easy, safe way to check what database a Drupal 8 install is using?

I'm trying to do a Drupal backup but when I look in phpmyadmin I see 5 different DBs listed on the left. I'd prefer to only backup the one I'm using because I've had issues before backing up and restoring the "under the hood" DBs like information_schema.

I've searched a bit but none of the suggestions I've found seem to apply to Drupal 8. Everything I see like this, this, this, etc is from 5+ years ago and says to check the sites/default/setting.php for a db_url line, but I don't see that in that file for my site. Has the location of this info moved in Drupal 8?

FYI:

  • I'm using Drupal 8.3.7 via Bitname WAMP
  • I know there are some good backup modules - I've already backed everything up via the "Backup and Restore" module, but I'm paranoid and like to do a parallel manual backup in case something goes wrong with the module-based backup.

Thanks.

1
  • You can install Drush and run 'drush status' in the site root and get information about your installation like db name, db username,port, hostname, drupal version etc. Also you can get the location of your settings.php which for Drupal 8 is same as drupal 7 Drupal Settings File : sites/default/settings.php Settings.php file contains the database name in $database array.
    – nit3ch
    Commented Feb 20, 2018 at 6:31

3 Answers 3

8

You can do it with drush status.

If you look for Database name line, you get that information.

You can also look in the Drupal settings file (sites/default/settings.php) and search for code similar to the following one.

$databases['default']['default'] = array(
  'database' => 'database_name',
);
1
  • Both options worked, thanks! Getting drush started in Bitnami is a bit tricky so the second option was easier for me.
    – SSilk
    Commented Feb 22, 2018 at 0:02
1

Using the following code, you can get the connection information that is set in the settings.php file used by the site where the code is executed.

$connection = \Drupal::database();
$options = $connection->getConnectionOptions();
$database = $options['database'];
print $database . "\n";
0

You can go to /admin/reports/status and check there.

status report

2
  • This shows what version (of MySQL?) was use to create the database, but it doesn't seem to show what the database name is, even in your screenshot.
    – SSilk
    Commented Feb 21, 2018 at 23:48
  • The OP said nothing about the database name. The wording of the question itself implies that though.
    – Kartagis
    Commented Feb 22, 2018 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.