Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a Drupal multisite that needs to have one database for each site, and want it to run in ddev, but ddev just has the one database by default, named 'db'. How can I get a second database?

like image 421
rfay Avatar asked Apr 11 '18 21:04

rfay


1 Answers

Youu 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
  • CREATE DATABASE newdb;
  • 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 https://github.com/drud/ddev-contrib/tree/master/recipes/drupal8-multisite

More details about database management at https://ddev.readthedocs.io/en/latest/users/topics/database_management/

like image 60
rfay Avatar answered Oct 08 '22 19:10

rfay