无法连接到 Bitbucket 管道上的 MySQL(111“连接被拒绝”)

Alf*_*Bez 1 mysql continuous-integration bitbucket

我尝试连接到 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")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是我的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'
Run Code Online (Sandbox Code Playgroud)

有什么想法我做错了吗?

小智 5

您忘记告诉您的服务实际使用 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'
Run Code Online (Sandbox Code Playgroud)