简体   繁体   中英

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.

I tried to use the parameter "command" in the Kubernetes yaml, but at the time of execution, the db is still not started.

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

you can create the pvc volume and start the container black without any database. 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.

start the container and go inside the container using exec mode and create a database and after that run this command

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? I need to execute during the initalization

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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