docker-compose.yml文件部署MySQL时出现错误?

作者站长头像
站长
· 阅读数 5

在Ubuntu中通过docker-compose部署MySQL时无法部署;docker-compose.yml文件如下:

version: '3'
services:
  mysql: 
    restart: always
    image: mysql:8.2
    network_mode: bridge
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root123
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /data/docker/mysql/mysql:/var/lib/mysql
      - /data/docker/mysql/etc:/etc/mysql:ro
    ports:
      - 3306:3306

我的步骤如下:1.注释挂载,直接启动mysql 成功2.复制容器中的/var/lib/mysql到宿主机我希望挂载的地方3.复制/etc/mysql ,然后编写my.cnf放到宿主机/data/docker/mysql/etc/mysql/conf.d下4.删除镜像5.打开注释错误如下:

2024-01-21 12:00:35+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
2024-01-21 12:00:35+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
    command was: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M --verbose --help --log-bin-index=/tmp/tmp.5xbHMoySK8
    mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/my.cnf at line 36.
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
回复
1个回答
avatar
test
2024-06-21

配置:

      - /data/docker/mysql/etc:/etc/mysql:ro

错误:

mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)

你的 /data/docker/mysql/etc 里没有 conf.d ,它被挂载到了 /etc/mysql/ ,导致启动的时候找不到 /etc/mysql/conf.d 。

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容