Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,032
Community Members
 
Community Events
176
Community Groups

How do I use MySQL in Bitbucket Pipelines

SebC Atlassian Team Apr 12, 2017

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

4 answers

1 accepted

1 vote
Answer 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.

Like # people like this

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

How did you manage to solve it?

Like Дмитрий likes this

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
SebC Atlassian Team Apr 26, 2017

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.

So, this is still broken, and the documentation is still giving you examples that don't work. Is a fix coming any time?

Like # people like this

+ mysql -u root -p root -h 127.0.0.1 < test.sql

bash: mysql: command not found

 

while running it i got this error

Like Leonid Lezner likes this

Try to install something that provides mysql command. For example on Debian image (in my case "php:7.1.29") this installs the standard mysql client:

- apt-get update && apt-get install -y mysql-client

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. 

Ensure your connecting to the DB with the hostname 127.0.0.1 and not "localhost" as the latter means nothing in docker.

I eventually got this working. But how can I change the mysql cnf file and then reboot the mysql server/service?
Really struggling with this bit, if anyone has any ideas?

Somehow this does not work for me, here's my bitbucket-pipelines.yml:

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'

 Output:

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

 Auswahl_767.png

I forgot to add the service to the pull-requests pipeline:

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'

Hi @Alfred_Bez did you experience this error after mentioning services tag in you yml file as well or was it gone? since my pipelines file is through me same error but not everytime time only sometimes i do have this *services* tag but its very unusual sometimes pipeline throws this error and sometime it passes build successfully for the same file. 

 

Any help will be appreciated if you know anything.

Thanks

Hello @Usama Habib , it works now for me, I don't see the error at all.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events