<p>I'm trying to pass mysql configuration with kubernetes configmap and PV , PVC and i'm getting error.</p>
<pre><code>chown: /var/lib/mysql/..data: Read-only file system
chown: /var/lib/mysql/crud.sql: Read-only file system
chown: /var/lib/mysql/..2021_12_29_12_32_17.053559530: Read-only file system
chown: /var/lib/mysql/..2021_12_29_12_32_17.053559530: Read-only file system
chown: /var/lib/mysql/: Read-only file system
chown: /var/lib/mysql/: Read-only file system
</code></pre>
<p>if im not <code>initContainers</code> using the im getting error:</p>
<pre><code>2021-12-29 12:49:05+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
chown: changing ownership of '/var/lib/mysql/': Read-only file system
chown: changing ownership of '/var/lib/mysql/..data': Read-only file system
chown: changing ownership of '/var/lib/mysql/crud.sql': Read-only file system
chown: changing ownership of '/var/lib/mysql/..2021_12_29_12_43_00.339135384': Read-only file system
chown: changing ownership of '/var/lib/mysql/..2021_12_29_12_43_00.339135384/crud.sql': Read-only file system
</code></pre>
<p><strong>Deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.deployment.mysql.name }}
  namespace: {{ .Values.namespace }}
spec:
  selector:
    matchLabels:
      app: {{ .Values.deployment.mysql.name }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ .Values.deployment.mysql.name }}
    spec:
      # initContainers:
      # - name: chmod-er
      #   image: busybox:latest
      #   command:
      #   - /bin/chown
      #   - -R
      #   - &quot;999:999&quot; 
      #   - /var/lib/mysql
      #   volumeMounts:
      #   - name: cm2
      #     mountPath: /var/lib/mysql

      containers:
      - image: {{ .Values.deployment.mysql.image }}
        name: {{ .Values.deployment.mysql.name }}
        securityContext:
          runAsUser: 0
        env:
         - name: MYSQL_ROOT_PASSWORD
           valueFrom: 
             secretKeyRef:
              name: mysql-secret
              key: mysql-root-password
        ports:
        - containerPort: {{ .Values.deployment.mysql.port }}
          name: {{ .Values.deployment.mysql.name }} 
        volumeMounts:
        - name: cm2
          mountPath: /var/lib/mysql/
          readOnly: false
      volumes:
      - name: mysqlvolume
        persistentVolumeClaim:
          claimName: mysqlvolume
          readOnly: false
      - name: cm2
        configMap:
          name: cm2
</code></pre>
<p>as you can see i tried with <code>initContainers</code> but sill got the same error.</p>
<p><strong>pv.yaml</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysqlvolume
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: C:\Users\ib151w\.minikube\volume
</code></pre>
<p><strong>pvc.yaml</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysqlvolume
  namespace: {{ .Values.namespace }}
  namespace: app
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Mi
</code></pre>
<p><strong>configmap.yaml</strong></p>
<pre><code>apiVersion: v1
data:
  crud.sql: |-
    /*!40101 SET NAMES utf8 */;
    /*!40014 SET FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
    /*!40111 SET SQL_NOTES=0 */;
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ crud /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
    USE crud;

    DROP TABLE IF EXISTS books;
    CREATE TABLE `books` (
      `id` int NOT NULL AUTO_INCREMENT,
      `first_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `last_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `department` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `manager` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
      `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
kind: ConfigMap
metadata:
  creationTimestamp: &quot;2021-12-29T10:24:41Z&quot;
  name: cm2
  namespace: app
  resourceVersion: &quot;6526&quot;
  uid: 31ab7ef8-94a4-41d3-af19-ddfceb04e124
</code></pre>
<p>im just trying to pass this configuration to the pod when it starting soo the mysql pod will be with the databases i want .</p>

ITBYD
<p>You're mounting configMap(<code>cm2</code>), and k8s mounts <code>configMap</code>s as readonly. Did you mean to mount <code>mysqlvolume</code> under <code>/var/lib/mysql/</code> and mount <code>cm2</code> somewhere else?  Mysql <code>/var/lib/mysql</code> is a data directory where MySQL writes <code>tablespace</code> data and it's not where you mount <code>configMap</code></p>
<p>If so:</p>
<pre><code>volumeMounts:
        - name: cm2
        - mountPath: /var/lib/mysql/
</code></pre>
<p>This should be changed to</p>
<pre><code>volumeMounts:
        - name: mysqlvolume
        - mountPath: /var/lib/mysql/

volumeMounts:
        - name: cm2
        - mountPath: ~/db_scripts ( or any other path)
</code></pre>
<p>You also need to execute the command <code>mysql &lt; ~/db_scripts/crud.sql</code> on container to create tables.</p>
