添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

问题:

新建了一个docker-compose.yaml配置,然后启动服务,发现连不上mysql
报错:Access denied for user

分析:

  1. 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: {}
  2. 进入mysql容器,docker exec -it mysql /bin/bash,env查看MYSQL_ROOT_PASSWORD的变量值,发现是MYSQL_ROOT_PASSWORD=1234
  3. 故障点定位到,environment的MYSQL_ROOT_PASSWORD这种赋值方式异常

解决办法或者注意事项:

  1. 查看官网关于环境变量定义的标准用法
    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
  2. 修正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: {}
  3. 登录mysql容器,env校验参数成功
  4. 标签: docker-compose

  5. windows家庭版启用远程桌面和query命令及启用关闭远程以后的自动化渲染
  6. ImportError: cannot import name 'NoReturn'"
  7. 关于docker-compose.yaml传递特殊字符的环境变量问题
  8. Typora提示The beta version of typora is expired解决
  9. 关于selenium无法通过tuniu网站滑动验证码的解决办法
  10. 指定vscode的debug程序启动路径
  11. win11体验安装Android应用
  12. windows安装和使用kubernetes
  13. 关于前后端分离,前端日常开发模式
  14. vscode关于settings sync同步失败,插件市场已不存在该插件的处理办法