无法在位桶管道上连接到MySQL(111“连接被拒绝”)

时间:2019-07-04 07:44:23

标签: mysql continuous-integration bitbucket

我尝试连接到我的Bitbucket管道中的数据库,并按照docs中所述使用服务定义,但是出现以下错误:

+ 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")

enter image description here

这是我的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'

有什么想法我做错了吗?

1 个答案:

答案 0 :(得分:1)

您忘了告诉您的服务实际使用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'