8

I'm trying to setup a MySQL pod on Digital Ocean with Kubernetes.

I kept getting this error:

Initializing database
2019-03-05T14:32:58.707421Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-05T14:32:58.708753Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-03-05T14:32:58.711746Z 0 [ERROR] Aborting

My yaml as a lot of stuff but the lines that interest this part of the config are the following.

# ------------------- Persistent Volume Claim ------------------- #

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-mysql-volume-claim
  ...
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: do-block-storage

---

# ------------------- Deployment ------------------- #

kind: Deployment
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
...
spec:
      ...
    spec:
      containers:
        - image: mysql:5.7
          ...
          volumeMounts:
            - name: test-mysql-volume
              mountPath: "/var/lib/mysql"
      volumes:
        - name: test-mysql-volume
          persistentVolumeClaim:
            claimName: test-mysql-volume-claim

---

If I comment out the PVC and the lines relative to PVC in the deployment config, everything works.

Also, if I change

mountPath: "/var/lib/mysql"

to

mountPath: "/data"

it works. But I obviously need /var/lib/mysql...

It happens also on brand new clusters.

Any idea?

6
  • Apparently it has been a known issue since 2015! Commented Mar 5, 2019 at 14:57
  • Can you provide output of kubectl get pv Commented Mar 6, 2019 at 12:32
  • Are you using your own mysql image? Commented Mar 6, 2019 at 12:39
  • Sometimes you just change path rather than overcome the obstacle. Commented Mar 7, 2019 at 20:54
  • I was using the latest official mysql image, but then I went back to the MariaDB. Anyway if can backup the volume, deleting and restarting from scratch is the quickest solution. Commented Mar 7, 2019 at 20:56

4 Answers 4

17

I had this issue with Kubernetes and MySQL 5.7 as well.

Adding the suggestion from yosifki to my container's definition got things working.

A new ext4 disk partition is not usually empty; there is a lost+found directory, which mysql is known to choke on. You could try adding --ignore-db-dir=lost+found to the CMD to know for sure (from mysql docs)

Here's an extract of my working YAML definition:

name: mysql-master
image: mysql:5.7
args:
  - "--ignore-db-dir=lost+found"
Sign up to request clarification or add additional context in comments.

Comments

6

I had a similar problem.

Using mysql:5.6 fixed it.

For more information refer to:

https://github.com/docker-library/mysql/issues/69

https://github.com/docker-library/mysql/issues/186

Comments

2

I have come across this issue. Work around is to delete the pv and pvc and recreate them.

1 Comment

i've deleted minikube. for nothing
1

The do-block-storage StorageClass you were using might have been formatted with the ext2/3/4 file system, which usually creates a lost+found directory at the root.

In addition to using the --ignore-db-dir=lost+found option as suggested by Thiago, you can also add subPath to your entry in the volumeMounts like this:

...
          volumeMounts:
            - name: test-mysql-volume
              mountPath: "/var/lib/mysql"
              subPath: mysql
...

If you add another container to the pod and mount the volume normally (without using subPath), you will see something like this:

root@test-mysql-4355v8b79q-cb97l:/# ls -la /data/
total 24
drwxr-xr-x. 4 root root  4096 Jun 28 02:23 .
drwxr-xr-x. 1 root root    29 Jun 28 02:25 ..
drwx------. 2 root root 16384 Jun 28 02:23 lost+found
drwxr-xr-x. 5  999 root  4096 Jun 28 02:25 mysql

I personally like this method because it should also work with images that require an empty directory but don't have any option to ignore the lost+found directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.