Docker 修改Data目录后MySQL启动失败的问题

0
(0)

错误日志类似如下信息:

2023-10-31 02:23:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
2023-10-31 02:23:24+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-10-31 02:23:24+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2023-10-31T02:23:26.014670Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2023-10-31T02:23:26.761643Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-10-31T02:23:26.775407Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.1.0) starting as process 1
2023-10-31T02:23:26.990797Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysqld: Can't create/write to file '/tmp/ibwJSudB' (OS errno 13 - Permission denied)
2023-10-31T02:23:27.807788Z 1 [ERROR] [MY-012576] [InnoDB] Unable to create temporary file inside "/tmp"; errno: 13
2023-10-31T02:23:27.807976Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2023-10-31T02:23:27.808257Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2023-10-31T02:23:27.808924Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2023-10-31T02:23:27.809157Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-10-31T02:23:27.812428Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.1.0)  MySQL Community Server - GPL.
2023-10-31T02:23:27.826107Z 0 [System] [MY-015016] [Server] MySQL Server - end.

解决办法:

1、找到tmp目录,设置tmp目录的权限为777

armbian:~:# docker inspect --format '{{ .GraphDriver.Data.UpperDir }}' wpmysql
/data/docker/overlay2/d429f4b553309e5afc0967b36ddb2e7871699eab9a110b4cd4c231336ef6624a/diff

我这个MySQL使用的 tmp 目录是在diff这层里,使用ls可以看到,直接 执行chmod设置权限

chmod -Rf 777 tmp

2、再次启动MySQL容器即可。

可以看到日志正常:

2023-10-31T02:36:28.056725Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2023-10-31T02:36:28.584963Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-10-31T02:36:28.591179Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.1.0) starting as process 1
2023-10-31T02:36:28.630265Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-10-31T02:36:34.411017Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-10-31T02:36:39.056752Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-10-31T02:36:39.056991Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-10-31T02:36:39.641078Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2023-10-31T02:36:39.641863Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.1.0'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

这篇文章有用吗?

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?