How can I create and load a second database in ddev?

I like the approach of creating an additional config.multisite.yaml and add add the definition there:

  - basic
  - umami
  - exec: mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS basic; GRANT ALL ON basic.* to 'db'@'%';"
    service: db
  - exec: mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS umami; GRANT ALL ON umami.* to 'db'@'%';"
    service: db

Above is from ddev-contrib recieps

You can import additional databases directly with ddev import-db --target-db=newdb. The created database will already have permissions, etc.

You can also manually create and manage databases (although this is rarely necessary any more). The root password for the db server is 'root', so you can mysql -uroot -proot in there (or use ddev mysql -uroot -proot).

  • ddev mysql -uroot -proot
  • GRANT ALL ON newdb.* to 'db'@'%' IDENTIFIED BY 'db';
  • Now, if you want to load from a db dump, ddev import-db --target-db=newdb --src=dumpfile.sql
  • Your normal web user can now access this alternate db, and it can be used in the settings.php for your alternate multisite.
  • There are many other things you'll want to do for your Drupal multisite; there is a full tutorial at

More details about database management at

In addition to rfay answer, The trick used in the last link was exactly what I wanted to propose and what I'm currently using:

Add this hook to the config.yml file

  - exec: mysql -uroot -proot -hdb -e "CREATE DATABASE IF NOT EXISTS second_db; GRANT
      ALL ON second_db.* TO 'db'@'%';"

And load data to the second database by using the param --target-db:

ddev import-db --target-db=second-db --src=second-db.sql