首页 > 解决方案 > 无法在 bitbucket 管道上连接到 MySQL(111“连接被拒绝”)

问题描述

我尝试连接到我的 bitbucket 管道中的数据库并使用文档中描述的服务定义,但出现以下错误:

+ mysql -h 127.0.0.1 -u root -ptest_user_password -e "SHOW DATABASES"
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")

在此处输入图像描述

这是我的bitbucket-pipelines.yaml

image: debian:stretch

pipelines:
  pull-requests:
    '*':
      - step:
          script:
            - apt-get update && apt-get install -y mysql-client
            - mysql -h 127.0.0.1 -u root -ptest_user_password -e "SHOW DATABASES"
definitions:
  services:
    mysql:
      image: mysql:5.7
      variables:
        MYSQL_DATABASE: 'pipelines'
        MYSQL_ROOT_PASSWORD: 'test_user_password'

任何想法我做错了什么?

标签: mysqlcontinuous-integrationbitbucket

解决方案


您忘记告诉您的服务实际使用 mysql 服务。试试那个配置:

image: debian:stretch

pipelines:
  pull-requests:
    '*':
      - step:
          script:
            - apt-get update && apt-get install -y mysql-client
            - mysql -h 127.0.0.1 -u root -ptest_user_password -e "SHOW DATABASES"
          services:
            - mysql
definitions:
  services:
    mysql:
      image: mysql:5.7
      variables:
        MYSQL_DATABASE: 'pipelines'
        MYSQL_ROOT_PASSWORD: 'test_user_password'

推荐阅读