You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CircleCI 2中使用circleci/mysql时caching_sha2_password插件加载失败求助

解决CircleCI 2中MySQL认证插件加载失败的问题

嘿,这问题我之前也踩过坑,咱们一步步来搞定它!

问题根源

你碰到的ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded错误,本质是circleci/mysql镜像默认启用了MySQL 8.0+的新认证机制caching_sha2_password,但CircleCI环境里的MySQL客户端不支持这个插件,导致连接失败。

两种可行的解决方案

方案1:修改MySQL容器启动命令,切换回旧认证方式

直接在config.yml里给circleci/mysql镜像加上启动参数,强制它使用兼容性更好的mysql_native_password认证:

jobs:
  build:
    docker:
      ...
      - image: circleci/mysql
        command: --default-authentication-plugin=mysql_native_password
      - image: rabbitmq:3-alpine
    working_directory: ~/webapp
    steps:
      ...
      - run:
          name: Prepare DB
          command: echo "create database" | mysql --host 127.0.0.1 -uroot

小提醒:CircleCI的MySQL容器默认root用户无密码,所以连接时一定要加上-uroot参数哦。

方案2:连接时直接指定认证插件

如果不想修改容器配置,也可以在mysql命令里直接指定使用旧认证插件:

- run:
    name: Prepare DB
    command: echo "create database" | mysql --host 127.0.0.1 -uroot --default-auth=mysql_native_password

额外小贴士

  • 如果需要给root用户设置密码,可以给circleci/mysql镜像添加环境变量:
    - image: circleci/mysql
      environment:
        MYSQL_ROOT_PASSWORD: your_secure_password
      command: --default-authentication-plugin=mysql_native_password
    
    之后连接命令要改成mysql --host 127.0.0.1 -uroot -pyour_secure_password

内容的提问来源于stack exchange,提问作者simen-andresen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:01:07