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

被刻印的时光 ゝ 提交于 2019-11-29 08:11:11

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.

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