How do I get a mysql database to run with by pipeline?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Having the same problem, obviously the configuration posted above and the one in the docs are broken.
How did you manage to solve it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had the same issue and i changed to MYSQL_DATABASE: 'pipelines' for example
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@SebCPlease change documentation https://confluence.atlassian.com/bitbucket/how-to-run-common-databases-in-bitbucket-pipelines-891130454.html to use
MYSQL_USER
in MySQL - test user section.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+ mysql -u root -p root -h 127.0.0.1 < test
.sql
bash: mysql: command not found
while running it i got this error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ensure your connecting to the DB with the hostname 127.0.0.1 and not "localhost" as the latter means nothing in docker.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.