如何在ddev中创建和加载第二个数据库? [英] How can I create and load a second database in ddev?

查看:103
本文介绍了如何在ddev中创建和加载第二个数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Drupal多站点,每个站点需要一个数据库,并希望它在ddev中运行,但是ddev默认只有一个数据库,名为"db".如何获得第二个数据库?

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?

推荐答案

这并不难,但是我认为目前还没有文档记录,而且绝对适合高级用户使用. MariaDB容器的根密码为"root",因此您可以在其中输入mysql -uroot -proot,也可以在主机上进行输入.假设您的主机上装有mysql客户端,则可以执行以下操作:

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:

  • 使用ddev describe获取mysql命令和端口号.
  • 在此处更改命令以使用用户名= root,密码= root.例如,在一个测试站点上,我有mysql --host=127.0.0.1 --port=32841 --user=root --password=root. 您的端口将不同.
  • CREATE DATABASE newdb;
  • GRANT ALL ON newdb.* to 'db'@'%' IDENTIFIED BY 'db';
  • 现在,如果要从数据库转储中加载,请mysql --host=127.0.0.1 --port=32841 --user=root --password=root --database=newdb <dumpfile.sql
  • 您的普通Web用户现在可以访问此备用数据库,并且可以在您的备用多站点的settings.php中使用它.
  • 请注意,对于多站点,您需要添加额外的 additional_hostnames 到您的ddev项目.
  • 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.

或者,您可以使用phpmyadmin(请参阅ddev describe中的URL)执行此操作,但是首先您必须向phpmyadmin使用的"db"用户授予完全特权,然后将出现phpmyadmin中的创建"按钮.

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'@'%';

请参见 ddev如何自动创建其他数据库?

如何为项目自动创建其他数据库.

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

这篇关于如何在ddev中创建和加载第二个数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆