Initializing mysql directory error

Pls, read error carefully:

[ERROR] --initialize specified but the data directory has files in it. Aborting.

Your directory is not empty. You have to remove all the contents of it or choose another one.


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"

And here, a docker-compose snippet for better clarify:

version: '3'
services:
  mysql-master:
    image: mysql:5.7
    command: [--ignore-db-dir=lost+found]
    environment:
      - MYSQL_ROOT_PASSWORD=root

Tags:

Mysql

Php