<p>I need to start a MySQL container in Kubernetes with a database and a schema and sample data.</p>

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

<pre class="lang-sql prettyprint-override"><code>        - 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"
</code></pre>

<p>Solved adding </p>

<pre><code>      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
</code></pre>
