How do I use MySQL in Bitbucket Pipelines

How do I get a mysql database to run with by pipeline?

2 answers

1 accepted

You'll want to take advantage of services in bitbucket pipelines.

For the simple uses, you can create an empty database named 'pipelines' and use the 'root' user with password 'let_me_in' to connect on localhost:3306

 

pipelines:
  default:
    - step:
        image: node
        script:
          - npm install
          - npm test
        services:
          - mysql
 
definitions:
  services:
    mysql:
      image: mysql
      environment:
        MYSQL_DATABASE: pipelines
        MYSQL_ROOT_PASSWORD: let_me_in

For more complex situations, you can create a test user to help validate database permissions and other priviledged settings.

The below bitbucket-pipelines.yml will create an empty database named 'pipelines' and user 'test_user' with password 'let_me_in' to connect on localhost:3306. The root user will have a random password created for it and not be accessible.

pipelines:
  default:
    - step:
        image: node
        script:
          - npm install
          - npm test
        services:
          - mysql
 
definitions:
  services:
    mysql:
      image: mysql
      environment:
        MYSQL_DATABASE: pipelines
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USERNAME: test_user
        MYSQL_PASSWORD: test_user_password

 

I tried with your configuration above:

MYSQL_DATABASE: pipelines
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_USERNAME: test_user
MYSQL_PASSWORD: test_user_password

but Pipeline said to me that:

The 'environment' section in your bitbucket-pipelines.yml file must be a map.

Obviously it was a map. I remove this environment and put original ones, taken from mysql docker hub page. It worked.

Probably this configuration is broken and you should update your documentation.

Having the same problem, obviously the configuration posted above and the one in the docs are broken.

How did you manage to solve it?

I had the same issue and i changed to MYSQL_DATABASE: 'pipelines' for example

Got it working with the following config:

environment:
MYSQL_DATABASE: pipelines
MYSQL_ROOT_PASSWORD: root_user_password
MYSQL_USER: test_user
MYSQL_PASSWORD: test_user_password

Thanks for the feedback! Turns out there was an issue where values like "yes" or "true" are being converted to booleans, which is causing some problems when they're loaded into the service container (yes becomes true for example).

Quoting these values will force them to be treated as strings - I'll be discussing this within the Pipelines team to try and improve the experience.

I just can't make this work. I get a `Exception: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known` no matter what I do. I have tried a regular user and root user. I also tried using the hostname `mysql`. Nothing works. Can anyone confirm that this is actually a working thing?

I also get a `mysqld: Shutdown complete` at the end of the database service log. Why?

Just wondering if anyone got a solution to this issue.

I am experiencing same issue with similar mysql configuration. My pipeline reports php_network_getaddresses failure. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

78 views 0 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you