mysql service import database

Vincent Gabriel March 4, 2018

Hey,

I am trying to load the schema.sql file into the mysql service but it seems that mysql is not ready at that time. i am not even sure if it's available since it's running on a separate docker as it seems.

What's the best solution for this to be able to load the sql schema?

Thank You.

 

image: edbizarro/bitbucket-pipelines-php7

pipelines:
default:
- step:
caches:
- composer
services:
- redis
- mysql
script:
- cp .env.build .env
- mysql -u root -proot -f avncms < database/schema/schema.sql
- composer install --no-interaction --no-progress --prefer-dist --no-scripts
- php artisan tools:deploy --no-interaction
- yarn
- vendor/bin/phpunit

definitions:
services:
redis:
image:
redis
mysql:
image:
mysql
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'avncms'
MYSQL_RANDOM_ROOT_PASSWORD: 'no'
MYSQL_USER: 'test_user'
MYSQL_PASSWORD: 'test_user_password'

1 answer

0 votes
Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2018

Does the database exist on the docker prior to the import?

Vincent Gabriel March 5, 2018

 

Screen Shot 2018-03-05 at 10.25.16 AM.pngI don't think so but i am not sure how to check if it's available at the time it tries to import.

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2018

You could add an extra step to ensure it is there prior to the import using the following syntax.

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name

That would cover that possible problem, then we can see what happens next.

Vincent Gabriel March 5, 2018

Yeah it does not exist at that time.

 

+ mysql -u root -proot -e "CREATE DATABASE avncms"

mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

 

It seems that the service is not ready or i can't access the mysql service from the build container.

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2018

Can you try using the other mysql user you are creating (test_user) to check that mysql is available, it looks like root access to mysql is not going to work.

Vincent Gabriel March 6, 2018

same issue.

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2018

I've just noticed in your above screenshot that you are running a version check on mysql, followed by a ps -ef.

It looks like you aren't seeing the mysql process running, so I would guess the version check is failing too.

I just built a quick pipeline test using a similar config file and don't see mysql started either.

Will check a bit more later on.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events