Adam Copley
Adam Copley

Reputation: 1495

Accessing mysql from build commands in bitbucket pipelines

I'm getting ERROR 2002 (HY000): Can't connect to local MySQL when trying to execute a mysql command during my CI process.

Here is my bitbucket-pipelines.yml file

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'

And here is the error:

+ 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

What do I need to do to be able to access mysql from this command line?

Upvotes: 1

Views: 3569

Answers (1)

Yuri G.
Yuri G.

Reputation: 4648

look at their 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)

Upvotes: 3

Related Questions