2

I have Gitlab CI set-up but it keeps failing when trying to run the database migrations:

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = test_db and table_name = migrations)    

My gitlab.yml file is:

before_script:
  - bash .gitlab-ci.sh
  - export APP_ENV=testing

services:
  - mysql:8.0

variables:
  MYSQL_DATABASE: test_db
  MYSQL_ROOT_PASSWORD: testdb
  DB_HOST: mysql
  DB_USERNAME: root
  DOCKER_DRIVER: overlay

cache:
  paths:
  - vendor/
  - node_modules/

stages:
  - test
  - deploy

phpunit:php7.1:mysql8.0:
  stage: test
  image: php:7.1
  services:
    - mysql:8.0
  script:
    - echo "Running PHP Unit - php 7.1 mysql 8.0"
    - php vendor/bin/phpunit --colors

deploy_production:
  stage: deploy
  script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

    - ~/.composer/vendor/bin/envoy run deploy
  environment:
    name: production
    url: http://167.99.202.64

  when: manual
  only:
    - master

My before bash script is as follows:

#!/bin/bash

# Install dependencies only for Docker.
[[ ! -e /.dockerinit ]] && [[ ! -e  /.dockerenv ]] && exit 0
set -xe

# Update packages and install composer and PHP dependencies.
apt-get update -yqq
apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq

# Compile PHP, include these extensions.
docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache

# Install Composer and project dependencies
echo 'Installing composer'
curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-plugins --no-scripts --dev

# Copy over testing configuration.
cp .env.testing .env

# Generate an application key. Re-cache
php artisan key:generate
php artisan config:cache

# Run database migrations
php artisan migrate

Finally my env.testing file:

APP_ENV=testing
APP_DEBUG=true
APP_KEY=key

DB_HOST=mysql
DB_DATABASE=test_db
DB_USERNAME=root
DB_PASSWORD=testdb

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
MAIL_DRIVER=log

I'm guessing Laravel inside the PHP7.1 container can't see the MySQL container looking at the error message? Is declaring it as a service in the gitlab.yml not enough?

3 Answers 3

2

Update your .gitlab-ci.yml file and set mysql version to 5.7

services:
  - mysql:5.7
Sign up to request clarification or add additional context in comments.

Comments

2

Finally, i had same Problem with

service: -mysql:latest 

(since three Weeks the Builds are failing, because the latest label has moved to version 8)

The Problem is:

MySQL 8

When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server's default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used. [1]

Comments

1

You can redeclare an entrypoint for the MySql service like this:

services:
        - name: mysql:8.0
          alias: mysql-server
          entrypoint: ['/entrypoint.sh', '--default-authentication-plugin=mysql_native_password']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.