无法在Windows 10上初始化MySQL数据库 [英] Fails to initialize MySQL database on Windows 10

查看:534
本文介绍了无法在Windows 10上初始化MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Laradock

系统信息:

  • Docker版本:17.10.0-ce,构建f4ffd25
  • 操作系统:Windows 10 Home

运行docker-compose up -d mysql时出现错误.以下是docker日志

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

[注意] Basedir设置为/usr/

[Note] Basedir set to /usr/

[警告]语法'--symbolic-links/-s'已被弃用,并将在以后的版本中删除

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

[警告]'NO_ZERO_DATE','NO_ZERO_IN_DATE'和'ERROR_FOR_DIVISION_BY_ZERO'sql模式应与严格模式一起使用.它们将在以后的版本中以严格模式合并.

[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.

[错误]正在中止

我尝试删除~/.laradock\data下的mysql文件夹,但是没有用.

I have tried deleting mysql folder under ~/.laradock\data and didn't work.

更新1

laradock Dockerfile下的MySQL容器

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 <mahmoud@zalt.me>

#####################################
# 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

更新2

删除~/.laradock/data下的mysql文件夹后,出现以下错误.命令执行后,将在下图中生成文件.当我重新运行时,还给了上面提到的先前错误.

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.

[注意] Basedir设置为/usr/

[Note] Basedir set to /usr/

[警告]语法'--symbolic-links/-s'已被弃用,并将在以后的版本中删除

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

[警告]'NO_ZERO_DATE','NO_ZERO_IN_DATE'和'ERROR_FOR_DIVISION_BY_ZERO'sql模式应与严格模式一起使用.在将来的版本中,它们将与严格模式合并.

[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.

[警告]设置lower_case_table_names = 2,因为/var/lib/mysql/的文件系统不区分大小写

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

[警告]您需要使用--log-bin才能使--log-slave-updates工作.

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

libnuma:警告:/sys未安装或无效.假设一个节点:没有这样的文件或目录 mbind:不允许操作

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

[错误] InnoDB:文件操作中的操作系统错误号22.

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

[错误] InnoDB:错误号22表示 无效参数

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

[错误] InnoDB:文件 ./ib_logfile101:'aio write'返回了操作系统错误122.无法继续 操作

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

[错误] InnoDB:无法 继续操作.

[ERROR] InnoDB: Cannot continue operation.

**我在Windows 7机器上尝试了它的工作原理.

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

推荐答案

禁用AIO

这与我从Virtualbox的来宾Debian OS中启动容器并在Windows 10的共享文件夹上创建数据库文件时遇到的AIO错误一样,为我修复了此问题.

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.

问题似乎是共享文件夹或至少某些Windows版本不支持AIO.在我的主机崩溃后,我从Windows 10 Pro迁移到家庭版之后,这似乎对我来说是发生了.

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.

有关详细信息:

  • aio
  • disable aio in MySQL for zfs

以下是一些选择:

选项1-像这样启动容器:

docker run -it mysql --innodb_use_native_aio=0

选项2-将命令添加到您的docker-compose文件:

 command: --innodb_use_native_aio=0

在上下文中,这是我正在工作的docker-compose.yml的相关部分:

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

选项3-向构建中的my.cnf文件添加一个选项

innodb_use_native_aio=0

选项4-不要将数据库保留在本地文件系统上.(可以破坏数据库,不推荐)

只需在包含mysql数据库的docker配置中删除该卷即可.当然,如果您做一个docker-compose或破坏您的容器,您的数据库将被删除,就是这样.

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.

这篇关于无法在Windows 10上初始化MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆