简体   繁体   English

docker update 后,Mysql 未在 MacOS 上的 docker 容器中启动

[英]Mysql not starting in a docker container on MacOS after docker update

I just upgraded to Docker Desktop 2.4 on MacOS, from version 2.3.我刚刚从 2.3 版升级到 MacOS 上的 Docker Desktop 2.4。 Suddenly none of my mysql containers will start.突然,我的 mysql 容器都不会启动。 The logs show this as the reason:日志显示这是原因:

Different lower_case_table_names settings for server ('2') and data dictionary ('0').
Data Dictionary initialization failed.
Aborting

The database files are mounted in a volume on my host machine, so that they persist between restarts.数据库文件安装在我的主机上的一个卷中,以便它们在重新启动之间保持不变。

I finally figured out why.我终于明白为什么了。 Posting in order to answer.发帖是为了回答。

With the latest docker you can disable the gRPC Fuse for file sharing.使用最新的 docker,您可以禁用 gRPC Fuse 以进行文件共享。 (the gRPC Fuse setting is causing this problem, it's incompatible with the data dictionary of 0) (gRPC Fuse 设置导致了这个问题,它与 0 的数据字典不兼容)

截图泊坞窗

This fixes the problem... You can stop here if you're happy, but to use the new filesystem you can:这解决了问题...如果您满意,您可以在这里停下来,但是要使用新的文件系统,您可以:

  • Disable this checkbox禁用此复选框
  • Start the container启动容器
  • Dump the database转储数据库
  • Enable this checkbox启用此复选框
  • Make sure your data folder empty (so mysql creates a new data dictionary)确保您的数据文件夹为空(因此 mysql 创建一个新的数据字典)
  • Import the dumped database导入转储的数据库

UPDATE更新

Since version 2.5, the setting has been moved to the 'experimental features' page:从 2.5 版本开始,该设置已移至“实验功能”页面:

在此处输入图像描述

The lower_case_table_names setting tells mysql how to store and compare table names. lower_case_table_names设置告诉 mysql 如何存储和比较表名。 If the file system the database is stored on is itself not case-sensitive, it will force you to use lower_case_table_names=2 .如果存储数据库的文件系统本身不区分大小写,它将强制您使用lower_case_table_names=2

The MacOS filesystem is not case-sensitive. MacOS 文件系统不区分大小写。 Up until Docker Desktop 2.4, the mysql container apparently didn't know that the underlying filesystem is not case-sensitive and set lower_case_table_names=0 .直到 Docker Desktop 2.4,mysql 容器显然不知道底层文件系统不区分大小写并设置lower_case_table_names=0 However, since upgrading to Docker 2.4, Docker is apparently smarter about how it mounts volumes.然而,自从升级到 Docker 2.4 后,Docker 在如何挂载卷方面显然更聪明了。 So the container realizes its running on a case-insensitive filesystem and forces lower_case_table_names=2 .所以容器实现了它在不区分大小写的文件系统上运行并强制lower_case_table_names=2 The problem is that you cannot change the value of lower_case_table_names after initializing the database.问题是初始化数据库后不能更改lower_case_table_names的值。 And since the data dictionary was initialized with lower_case_table_names=0 , it will fail to initialize with the server set to lower_case_table_names=2 .并且由于数据字典是使用lower_case_table_names=0初始化的,因此在服务器设置为lower_case_table_names=2时它将无法初始化。

The only solution I've found is to:我发现的唯一解决方案是:

  1. Downgrade to Docker Desktop 2.3降级到Docker 桌面 2.3
  2. Backup the entire database 备份整个数据库
  3. Upgrade to Docker 2.4升级到 Docker 2.4
  4. Delete the volume storing the database.删除存储数据库的卷。
  5. Reinitialize the database.重新初始化数据库。
  6. Restore the database from backup.从备份中恢复数据库。

UPDATE: See this answer below for a better solution.更新:请参阅下面的答案以获得更好的解决方案。 There is apparently no need to downgrade.显然没有必要降级。 You can instead disable "gRPC Fuse for filesharing", backup the database, re-enable gRPC fuse, delete your database data folder, and restore the database from backup.您可以改为禁用“用于文件共享的 gRPC Fuse”,备份数据库,重新启用 gRPC fuse,删除数据库数据文件夹,并从备份中恢复数据库。

Another option is to create a case sensitive APFS volume using Disk Utility.另一种选择是使用磁盘工具创建区分大小写的 APFS 卷。

将 APFS 添加到容器 显示 APFS 卷之间的存储是共享的

Unlike a partition, it is possible to share the free space, so you don't need to worry about reserving enough space to run your database.与分区不同,它可以共享可用空间,因此您无需担心保留足够的空间来运行数据库。

Then create a symlink from your project to your case sensitive volume.然后创建一个从您的项目到区分大小写的卷的符号链接。

cd ~/my-project
ln -s /Volumes/MySQL/project-db mysql

Docker removed this option on the recent updates , i manage to solve this issue on windows by doing this Docker 在最近的更新中删除了这个选项,我通过这样做在 Windows 上解决了这个问题

Run a shell as administrator:以管理员身份运行 shell:

go to your local mounted mysql volume and run转到本地安装的 mysql 卷并运行

fsutil file setCaseSensitiveInfo ./ enable 

credits to https://github.com/docker/for-win/issues/12384#issuecomment-972845031归功于https://github.com/docker/for-win/issues/12384#issuecomment-972845031

A small addition to Loic's H answer. Loic 的 H答案的一个小补充。 Suppose your mapping is something like this:假设您的映射是这样的:

docker run --name your_container_name ... -v //d/MySqlDockerData:/var/lib/mysql ...

if your try如果你尝试

fsutil file setCaseSensitiveInfo d:\MySqlDockerData

you will get an error "The directory is not empty"你会得到一个错误“目录不为空”

To get around this follow these steps:要解决此问题,请执行以下步骤:

  1. run docker container stop your_container_name运行docker container stop your_container_name
  2. transfer the contents of the folder to the another place (clear the folder)将文件夹的内容转移到另一个地方(清除文件夹)
  3. run again fsutil file setCaseSensitiveInfo d:\MySqlDockerData再次运行fsutil 文件 setCaseSensitiveInfo d:\MySqlDockerData
  4. transfer back saved data to the d:\MySqlDockerData将保存的数据传输回 d:\MySqlDockerData
  5. run docker container start your_container_name运行docker 容器启动 your_container_name

voila

As workaround on Windows OS I disabled WSL in Docker Desktop and it helped me作为 Windows 操作系统上的解决方法,我在 Docker Desktop 中禁用了 WSL,它帮助了我

Update .更新 After last Docker Desktop Updates I was forced to set Windows directory with DB data as case sensitive在上次 Docker 桌面更新之后,我被迫将带有 DB 数据的 Windows 目录设置为区分大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM