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

纵然是瞬间 提交于 2019-11-28 01:42:38

问题


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:


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.



来源:https://stackoverflow.com/questions/49785023/how-can-i-create-and-load-a-second-database-in-ddev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!