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?
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