使用 Docker Compose 部署 MySQL 時(shí),遇到 “mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’” 錯誤如何解決?

使用 Docker Compose 部署 MySQL 時(shí),遇到 “mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’” 錯誤如何解決?

mysql docker 部署疑難解答

本文旨在解決在 ubuntu 環(huán)境中使用 docker-compose 部署 mysql 時(shí)遇到的錯誤問題。

問題描述:

用戶在執(zhí)行以下 docker-compose.yml 文件時(shí)遇到了錯誤:

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

錯誤信息如下:

mysqld: can't read dir of '/etc/mysql/conf.d/' (os errno 2 - no such file or directory)

解決方法:

錯誤源于 /etc/mysql/conf.d/ 目錄不存在。該目錄用于存儲 mysql 配置文件,而 docker-compose 配置將 /data/docker/mysql/etc 掛載到了 /etc/mysql/ 上。

要解決此問題,需要確保 /data/docker/mysql/etc 目錄中存在 conf.d 子目錄,并將其掛載到 /etc/mysql/conf.d/ 上。修改后的 docker-compose 如下:

volumes:   - /etc/localtime:/etc/localtime:ro   - /data/docker/mysql/mysql:/var/lib/mysql   - /data/docker/mysql/etc/conf.d:/etc/mysql/conf.d:ro

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊8 分享