简体   繁体   English

如何在Kubernetes中使用示例数据启动mysql容器?

[英]How to start a mysql container in Kubernetes with sample data?

I need to start a MySQL container in Kubernetes with a database and a schema and sample data. 我需要在Kubernetes中使用数据库,模式和示例数据启动MySQL容器。

I tried to use the parameter "command" in the Kubernetes yaml, but at the time of execution, the db is still not started. 我试图在Kubernetes yaml中使用参数“ command”,但是在执行时,数据库仍未启动。

        - image: mysql:5.7.24
          name: database
          command:
            [
              '/usr/bin/mysql -u root -e "CREATE DATABASE IF NOT EXISTS mydbname"',
            ]
          env:
            - name: MYSQL_ALLOW_EMPTY_PASSWORD
              value: "1"

you can first create the container of mysql and later import the data of mysql it will that way. 您可以先创建mysql的容器,然后再以这种方式导入mysql的数据。

you can create the pvc volume and start the container black without any database. 您可以创建pvc卷并启动没有任何数据库的黑色容器。 you can use the command exec to import the sql while and data to the database which will create the database and sample data inside the container. 您可以使用命令exec将sql while和数据导入数据库,这将创建数据库并在容器内采样数据。

start the container and go inside the container using exec mode and create a database and after that run this command 启动容器并使用exec模式进入容器并创建数据库,然后运行此命令

kubectl exec -i <container name> -- mysql -h <hostname> -u <username> -p<password> <databasename> > databasefile.sql

Solved adding 解决了添加

      volumeMounts:
        - name: initdb
          mountPath: /docker-entrypoint-initdb.d

...
  volumes:
    - name: initdb
      configMap:
        name: initdb-config

...
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: initdb-config
data:
  initdb.sql: |
      mysqlquery

I did the same the sql file is mounted but not executed, am I missing something? 我执行了相同的sql文件安装但未执行的操作,我是否缺少某些内容? I need to execute during the initalization 我需要在初始化过程中执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM