gpt4 book ai didi

mysql - Docker 中的多个 MariaDB 数据库

转载 作者:行者123 更新时间:2023-12-02 19:41:55 25 4
gpt4 key购买 nike

使用 Docker (v.2) 我在 docker-compose.yml 中设置了一个数据库:

mysql:
image: mariadb:latest
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: 'test'
MYSQL_DATABASE: 'test'
MYSQL_USER: 'test'
MYSQL_PASSWORD: 'test'

这很好用。我需要做什么才能在同一个容器中创建另一个数据库?

最佳答案

我知道您想在同一个容器中创建两个数据库,对吧?我认为这违背了微服务架构原则。

无论如何,我认为当您初始化一个新实例时这是可能的:

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order.

更新mariadb/mysql目录下的文件link :

DROP USER IF EXISTS 'MYSQL_USER';
CREATE USER 'MYSQL_USER'@'%';
CREATE DATABASE IF NOT EXISTS MYSQL_DATABASE;
GRANT ALL ON MYSQL_DATABASE.* TO 'MYSQL_USER'@'%' IDENTIFIED BY 'MYSQL_PASSWORD';
--------------your new NewDB----------------------
CREATE DATABASE IF NOT EXISTS NewDB;
GRANT ALL ON NewDB.* TO 'MYSQL_USER'@'%' IDENTIFIED BY 'MYSQL_PASSWORD';

关于mysql - Docker 中的多个 MariaDB 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50173296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com