问题:
新建了一个docker-compose.yaml配置,然后启动服务,发现连不上mysql
报错:Access denied for user
分析:
-
docker-compose.yaml配置如下:
version: "3.9"
services:
mysql:
image: mysql:5.7
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
environment:
- MYSQL_ROOT_PASSWORD=1234$56
restart: always
ports:
- "13306:3306"
volumes:
- mysql-data:/var/lib/mysql
- mysql-conf:/etc/mysql/conf.d
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- 18080:8080
depends_on:
- mysql
volumes:
mysql-data: {}
mysql-conf: {}
-
进入mysql容器,docker exec -it mysql /bin/bash,env查看MYSQL_ROOT_PASSWORD的变量值,发现是MYSQL_ROOT_PASSWORD=1234
-
故障点定位到,environment的MYSQL_ROOT_PASSWORD这种赋值方式异常
解决办法或者注意事项:
-
查看官网关于环境变量定义的标准用法
https://docs.docker.com/compose/compose-file/compose-file-v3/#environment
https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-docker-compose-file
-
修正docker-compose.yaml配置
version: "3.9"
services:
mysql:
image: mysql:5.7
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
environment:
- MYSQL_ROOT_PASSWORD=1234$$56
restart: always
ports:
- "13306:3306"
volumes:
- mysql-data:/var/lib/mysql
- mysql-conf:/etc/mysql/conf.d
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- 18080:8080
depends_on:
- mysql
volumes:
mysql-data: {}
mysql-conf: {}
-
登录mysql容器,env校验参数成功
标签:
docker-compose
-
windows家庭版启用远程桌面和query命令及启用关闭远程以后的自动化渲染
-
ImportError: cannot import name 'NoReturn'"
-
关于docker-compose.yaml传递特殊字符的环境变量问题
-
Typora提示The beta version of typora is expired解决
-
关于selenium无法通过tuniu网站滑动验证码的解决办法
-
指定vscode的debug程序启动路径
-
win11体验安装Android应用
-
windows安装和使用kubernetes
-
关于前后端分离,前端日常开发模式
-
vscode关于settings sync同步失败,插件市场已不存在该插件的处理办法