Sql script file is not getting copied to docker-entrypoint-initdb.d folder of mysql container?

6/6/2019

My init.sql (script) is not getting copied to docker-entrypoint-initdb.d. Note that the problem doesn't occur when I try to run it locally or on my server. It happens only when using the azure devops by creating build and release pipeline.

There seems to be a mistake in the hostpath(containing sql script) in the persistant volume YAML file in cases where the file is placed in the azure repos.

mysqlpersistantvolume.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-initdb-pv-volume
  labels:
    type: local
    app: mysql
spec:
  storageClassName: manual
  capacity:
    storage: 1Mi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/devops-sample"     //  main project folder in azure repos which 
                                   contains all files including sql script.


---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-initdb-pv-claim
  labels:
    app: mysql
spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi

mysql.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:

  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306


  selector:
    app: mysql

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        imagePullPolicy: "IfNotPresent"
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: root
        - name: MYSQL_PASSWORD
          value: kovaion
        - name: MYSQL_USER
          value: vignesh
        - name: MYSQL_DATABASE
          value: data-core         
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /docker-entrypoint-initdb.d
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-initdb-pv-claim

Currently the folder docker-entrypoint-initdb.d seems to be empty(nothing is getting copied). how to set the full host path in mysql persistant volume if the sql script is placed in the azure repos inside the devops-sample folder??

-- Swetha Swaminathan
azure-devops
kubernetes
persistent-volumes
sql

1 Answer

6/6/2019

Mysql data directory storage location is wrong. You should mount persistent storage to /var/lib/mysql/data

-- P Ekambaram
Source: StackOverflow