从 bitbucket 管道中的构建命令访问 mysql

Accessing mysql from build commands in bitbucket pipelines

我在 CI 过程中尝试执行 mysql 命令时收到 ERROR 2002 (HY000): Can't connect to local MySQL

这是我的 bitbucket-pipelines.yml 文件

image: theotherperson/php-ci:5.6

pipelines:
  default:
    - step:
        caches:
          - composer
        script:
          - apt-get update && apt-get install -y unzip mysql-client
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install --no-scripts --no-plugins
          - cp test-assets/vhosts/000-default.conf /etc/apache2/sites-enabled/000-default.conf
          - cp test-assets/hosts/hosts /etc/hosts
          - rm /var/www/html/index.html
          - cp -R $BITBUCKET_CLONE_DIR /var/www/html
          - service apache2 restart
          - mysql -u root -p$MYSQL_ROOT_PASSWORD -e "test < $BITBUCKET_CLONE_DIR/data/test/test.sql"
          - phantomjs --webdriver=4444 &
          - vendor/bin/behat -p test_behat
        services:
          - mysql

definitions:
  services:
    mysql:
      image: mysql
      environment:
        MYSQL_DATABASE: 'test'
        MYSQL_ROOT_PASSWORD: 'mypassword'

这里是错误:

+ mysql -u root -p$MYSQL_ROOT_PASSWORD -e "test < $BITBUCKET_CLONE_DIR/data/test/test.sql"
Enter password: ERROR 2002 (HY000): Can't connect to local MySQL

我需要做什么才能从此命令行访问 mysql?

看看他们documentation

Host name: 127.0.0.1 (avoid using localhost, as some clients will attempt to connect via a local "Unix socket", which will not work in Pipelines)