How do I use MySQL in Bitbucket Pipelines

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

2 answers

1 accepted

This widget could not be displayed.

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.

This widget could not be displayed.

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
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,205 views 8 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