How can I create and load a second database in dde

2019-01-26 01:04发布

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?

1条回答
放我归山
2楼-- · 2019-01-26 01:43

This isn't too hard, but I think it's undocumented at this point, and definitely for advanced users. The root password for the MariaDB container is 'root', so you can mysql -uroot -proot in there, and you can also do it on the host. Assuming you have the mysql client on your host, you can do this:

  • Use ddev describe to get the mysql command and port number.
  • Change the command there to use username=root, password=root. For example, on a test site I have, mysql --host=127.0.0.1 --port=32841 --user=root --password=root. Your port will be different.
  • CREATE DATABASE newdb;
  • GRANT ALL ON newdb.* to 'db'@'%' IDENTIFIED BY 'db';
  • Now, if you want to load from a db dump, mysql --host=127.0.0.1 --port=32841 --user=root --password=root --database=newdb <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.
  • Note that for multisite you'll need to add extra additional_hostnames to your ddev project.

Alternately, you can use phpmyadmin (see the url in ddev describe) to do this but first you have to grant full privileges to the 'db' user that phpmyadmin uses, then the "Create" button in phpmyadmin will appear.

ddev ssh -s db
mysql 
GRANT ALL ON *.* TO 'db'@'%';

See How can ddev automatically create additional databases? for how to automatically create an additional database for a project.

查看更多
登录 后发表回答