ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/run/mysqld/mysqld.sock’ (2)

Hi guys !
I have a little (big) issue with my gitlab-ci.yml :frowning:

I’m trying to run my tests PHPUnit on the pipeline but when I want to create a mysql database and to connect it, it fails.

This is my .gitlab-ci.yml :

image: jakzal/phpqa:php8.0

before_script:
        - composer install
                
stages: 
    - SecurityChecker
    - UnitTests

cache:
  paths:
    - vendor/
    - ~/.composer/cache/files    

#On teste qu'il n'y a pas de faille de sécurité dans les différentes librairies
security-checker:
    stage: SecurityChecker
    script:
        - local-php-security-checker composer.lock
    allow_failure: false

#On lance les tests unitaires PHP UNIT    
phpunit:
    stage: UnitTests
    services:
        - name: mysql:latest
    before_script:
        - apt-get update && apt-get dist-upgrade && apt-get install -y git libzip-dev autoconf build-essential pkg-config libmariadb-dev-compat libmariadb-dev default-mysql-client mariadb-client mariadb-server
        - curl -sSk https://getcomposer.org/installer | php -- --disable-tls && mv composer.phar /usr/local/bin/composer
        - docker-php-ext-install mysqli pdo pdo_mysql zip
        # Connect MySQL
        - echo "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');" | mysql -u root
        - echo "SELECT 'OK';" | mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -h mysql "$MYSQL_DATABASE"
        # Import BDD tests
        - mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -h localhost < "database.sql"
    script:
        - vendor/bin/phpunit --testdox
    allow_failure: false

This is the result :

Do you have any ideas fo my issue ?
I didn’t found anything on the different forums for now… :sleepy:

Thanks a lot !

1 Like