Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

docker - Fails to initialize MySQL database on Windows 10

Using Laradock

System Info:

  • Docker version: 17.10.0-ce, build f4ffd25
  • OS: Windows 10 Home

When I run docker-compose up -d mysql I'm getting error. Following is the docker logs

[Note] Basedir set to /usr/

[Warning] The syntax '--symbolic-links/-s' is deprecated and will be removed in a future release

[Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

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

[ERROR] Aborting

I have tried deleting mysql folder under ~/.laradockdata and didn't work.

Update 1

MySQL Container under laradock Dockerfile

mysql:
  build:
    context: ./mysql
    args:
      - MYSQL_VERSION=${MYSQL_VERSION}
  environment:
    - MYSQL_DATABASE=${MYSQL_DATABASE}
    - MYSQL_USER=${MYSQL_USER}
    - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    - TZ=${WORKSPACE_TIMEZONE}
  volumes:
    - ${DATA_SAVE_PATH}/mysql:/var/lib/mysql
    - ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
  ports:
    - "${MYSQL_PORT}:3306"
  networks:
    - backend

MySQL Dockerfile

ARG MYSQL_VERSION=8.0
FROM mysql:${MYSQL_VERSION}

MAINTAINER Mahmoud Zalt <[email protected]>

#####################################
# Set Timezone
#####################################

ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN chown -R mysql:root /var/lib/mysql/

ADD my.cnf /etc/mysql/conf.d/my.cnf

CMD ["mysqld"]

EXPOSE 3306

Update 2

After I delete mysql folder under ~/.laradock/data I'm getting following error. After the command it generates the files in below image. When I rerun giving back the previous error mentioned above.

[Note] Basedir set to /usr/

[Warning] The syntax '--symbolic-links/-s' is deprecated and will be removed in a future release

[Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

[Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive

[Warning] You need to use --log-bin to make --log-slave-updates work.

libnuma: Warning: /sys not mounted or invalid. Assuming one node: No such file or directory mbind: Operation not permitted

[ERROR] InnoDB: Operating system error number 22 in a file operation.

[ERROR] InnoDB: Error number 22 means 'Invalid argument'

[ERROR] InnoDB: File ./ib_logfile101: 'aio write' returned OS error 122. Cannot continue operation

[ERROR] InnoDB: Cannot continue operation.

enter image description here

** I tried in a windows 7 machine and its working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Disable AIO

This fixed it for me when I got the AIO error as you did when I was starting a container from a guest Debian OS from Virtualbox and creating the database files on a shared folder on Windows 10.

The issue seems to be that AIO is not supported on shared folders, or at least on some versions of Windows. It seems to have occurred for me after I moved from Windows 10 Pro to Home after my main machine crashed.

For details:

Here are some options:

Option 1 - start the container like this :

docker run -it mysql --innodb_use_native_aio=0

Option 2 - add the command to your docker-compose file:

 command: --innodb_use_native_aio=0

In context, this is the relevant portion of my working docker-compose.yml:

services:
   db:
     image: ${MYSQL_IMAGE}
     command: "--innodb_use_native_aio=0"
     volumes:
       - ${DB_DATA_PATH}:/var/lib/mysql
     ports:
        - ${MYSQL_PORT}:3306

Option 3 -- add an option to your my.cnf file in your build

innodb_use_native_aio=0

Option 4 - Don't persist your DB on the local file system.(Can destroy your db, Not Recommended)

Simply remove the volume in your docker configuration that contains your mysql db. Of course, your DB will be deleted if you do a docker-compose down or otherwise destroy your container, so there's that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...