本文正在参与「金石方案 . 瓜分6万现金大奖」

前言

前些天由于服务器扩容,需求进行断电,因而 Docker 被迫封闭了;

今日重启 MySQL 8 的容器时,遇到了一些问题,特写此篇博文记载;

lower_case_table_names 参数设置

在发动 MySQL 容器时,运用相关指令:

[root@localhost ~]# docker run ...
WARNING: IPv4 forwarding is disabled. Networking will not work.
6dc8fa34ff7...e3ed12a1b2f6e0edbc8e6

看着姿态应该是发动成功了,可是经过 docker ps 指令检查,发现并没有刚刚发动的 MySQL 容器;

那让我们看一下日志,排查一下问题,docker logs 6dc8fa34ff7...e3ed12a1b2f6e0edbc8e6

【问题解决】解决 Docker 二次重启 MySQL 8 遇到的一些问题

发现问题所在:

Different lower_case_table_names settings for server ('0') and data dictionary ('1').

依据字面意思理解一下便是:

服务器('0')和数据字典('1')的不同 lower_case_table_names 设置。

具体的话能够看到 官方文档:

If set to 0, table names are stored as specified and comparisons are case-sensitive. If set to 1, table names are stored in lowercase on disk and comparisons are not case-sensitive. If set to 2, table names are stored as given but compared in lowercase. This option also applies to database names and table aliases. For additional details, seeSection9.2.3, “Identifier Case Sensitivity”.

The default value of this variable is platform-dependent (seelower_case_file_system). On Linux and other Unix-like systems, the default is0. On Windows the default value is1. On macOS, the default value is2. On Linux (and other Unix-like systems), setting the value to2is not supported; the server forces the value to0instead.

You shouldnotsetlower_case_table_namesto 0 if you are running MySQL on a system where the data directory resides on a case-insensitive file system (such as on Windows or macOS). It is an unsupported combination that could result in a hang condition when running anINSERT INTO ... SELECT ... FROMtbl_nameoperation with the wrongtbl_namelettercase. WithMyISAM, accessing table names using different lettercases could cause index corruption.

An error message is printed and the server exits if you attempt to start the server with--lower_case_table_names=0on a case-insensitive file system.

The setting of this variable affects the behavior of replication filtering options with regard to case sensitivity. For more information, seeSection17.2.5, “How Servers Evaluate Replication Filtering Rules”.

It is prohibited to start the server with alower_case_table_namessetting that is different from the setting used when the server was initialized. The restriction is necessary because collations used by various data dictionary table fields are determined by the setting defined when the server is initialized, and restarting the server with a different setting would introduce inconsistencies with respect to how identifiers are ordered and compared.

It is therefore necessary to configurelower_case_table_namesto the desired setting before initializing the server.

正如官方文档所说,On Linux and other Unix-like systems, the default is0.,我用的系统是 Linux 的,因而 lower_case_table_names 默许值是 0,因而我需求对其进行改动,将其与数据字典共同,即 lower_case_table_names=1

TIP


lower_case_table_names 该参数为静态,可设置为0、1、2。

  • 0 — 大小写灵敏。(Unix,Linux 默许);
  • 1 — 大小写不灵敏。(Windows 默许);
  • 2 — 大小写不灵敏。(OS X 默许);

先将旧的容器移除:

docker rm 6dc8fa34ff7...e3ed12a1b2f6e0edbc8e6

然后再重新发动一遍容器:

docker run -d --name sid10t-mysql \
-v $(pwd)/mysql/data:/var/lib/mysql \
-v $(pwd)/mysql/conf:/etc/mysql \
-v $(pwd)/mysql/log:/var/log/mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=pwd \
mysql --lower-case-table-names=1

测试一下衔接,衔接成功,搞定!

【问题解决】解决 Docker 二次重启 MySQL 8 遇到的一些问题

IPv4 forwarding is disabled 参数设置

本以为处理上面的问题就功德圆满了,可是天不如人愿,当我运用长途衔接时,结果如下:

【问题解决】解决 Docker 二次重启 MySQL 8 遇到的一些问题

当运用 pymysql 衔接时也被告知衔接超时:

OperationalError: (2003, "Can't connect to MySQL server on '10.20.152.70' (timed out)")

那第一时间便是置疑 3306 是否没有对外敞开,因而直接防火墙敞开 3306 端口:

firewall-cmd --zone=public --add-port=3306/tcp --permanent

可是却发现 3306 端口一直是敞开状况的:

【问题解决】解决 Docker 二次重启 MySQL 8 遇到的一些问题

那就检查其占用情况,是否只允许本地拜访:

【问题解决】解决 Docker 二次重启 MySQL 8 遇到的一些问题

发现也不是这个问题;

突然想起,刚刚发动容器的时分,好像是弹出了一个警告:

WARNING: IPv4 forwarding is disabled. Networking will not work.

查阅资料后发现,是没有开启 IPv4 转发,网桥配置完后,需求开启转发,否则容器发动后,就会没有网络,

因而进行如下操作即可:

vim /etc/sysctl.conf

或许

vi /usr/lib/sysctl.d/00-system.conf

添加如下代码:

net.ipv4.ip_forward=1

重启 network 服务:

systemctl restart network

检查是否修改成功:

sysctl net.ipv4.ip_forward

完成之后重启新的 MySQL 容器,再运用长途衔接就能够连上了;

跋文

以上便是 【问题处理】处理 Docker 二次重启 MySQL 8 遇到的一些问题 的全部内容了,期望对大家有所协助!

上篇精讲:这是第一篇,没有上一篇喔~

我是,期待你的关注;

创作不易,请多多支持;

系列专栏:问题处理