声明:这是我在大学毕业后进入第二家互联网公司学习的内容


背景

服务器根路径磁盘快满了,检查下发现是docker的占用空间过大,所以我准备将docker的默认路径更换到一个2T的磁盘里

操作

/data是新磁盘的挂载路径

1
2
3
4
5
6
7
8
9
10
systemctl stop docker
cp -r /var/lib/docker /data/
vim /etc/docker/daemon.json
添加一行"graph": "/data/docker"

{
"registry-mirrors":["https://wghlmi3i.mirror.aliyuncs.com"],
"graph": "/data/docker"
}
systemctl start docker

docker info查看Docker Root Dir: /data/docker说明更换成功

结果docker ps -a查看发现数据库启动失败,看看报错

报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
docker logs -f mysql

2021-09-25 02:49:14+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.28-1debian9 started.
2021-09-25 02:49:14+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-09-25 02:49:14+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.28-1debian9 started.
mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
2021-09-25T02:49:14.878098Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-25T02:49:14.879458Z 0 [Note] mysqld (mysqld 5.7.28) starting as process 1 ...
2021-09-25T02:49:14.881740Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-09-25T02:49:14.881752Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-09-25T02:49:14.881754Z 0 [Note] InnoDB: Uses event mutexes
2021-09-25T02:49:14.881756Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-09-25T02:49:14.881757Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-09-25T02:49:14.881759Z 0 [Note] InnoDB: Using Linux native AIO
2021-09-25T02:49:14.881941Z 0 [Note] InnoDB: Number of pools: 1
2021-09-25T02:49:14.882025Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-09-25T02:49:14.883068Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-09-25T02:49:14.888269Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-09-25T02:49:14.889777Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-09-25T02:49:14.900994Z 0 [ERROR] InnoDB: Unable to open undo tablespace './/undo001'.
2021-09-25T02:49:14.901009Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2021-09-25T02:49:15.502467Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-09-25T02:49:15.502516Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-09-25T02:49:15.502529Z 0 [ERROR] Failed to initialize builtin plugins.
2021-09-25T02:49:15.502536Z 0 [ERROR] Aborting

一开始我只注意到了Unable to open undo tablespace ‘.//undo001’

网上搜了下,大多都是说找不到这个文件,需要手动备份

但是我docker-compose是写的相对路径的挂载文件,不应该找不到啊

然后我尝试把undolog/undo001文件改成undo0001

重启mysql,仍然报相同的错误

我觉得mysql根本没有读到这个路径,这是为什么呢

仔细看报错发现有段warning

1
World-writable config file '/etc/mysql/my.cnf' is ignored.

网上查了下 出现这个原因是my.cnf权限过大 应该改成644

解决问题

1
chmod 644 my.CNF

果断更改,重启后成功