Gitlab CI Symfony:SQLSTATE [HY000] [2002]连接被拒绝

巴登

每当有人推送代码时,我都会使用gitlab运行单元测试。在Composer安装期间出现此错误。

> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Creating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache


  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  



  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  



  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception

这是我的配置:

.gitlab-ci.yml文件

    # Select image from https://hub.docker.com/_/php/
    image: php:5.6

    # Select what we should cache
    cache:
      paths:
      - vendor/

    before_script:
    # Install ssh-agent if not already installed, it is required by Docker.
    # (change apt-get to yum if you use a CentOS-based image)
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'

    #

 Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)

# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")

# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

- cp ci/custom.ini /usr/local/etc/php/conf.d/custom.ini
- bash ci/docker_install.sh > /dev/null

# Install composer
- curl -sS https://getcomposer.org/installer | php

services:
- mysql:latest

variables:
  # Configure mysql service (https://hub.docker.com/_/mysql/)
  MYSQL_DATABASE: symfony
  MYSQL_ROOT_PASSWORD: root

# We test PHP5.6 (the default) with MySQL
test:mysql:
  script:
  # Install all project dependencies
  - php composer.phar install
  - phpunit --coverage-text --colors=never -c app/

parameters.yml.dist

parameters:
    database_host:     127.0.0.1
    database_port:     ~
    database_name:     symfony
    database_user:     root
    database_password: root

    mailer_transport:  smtp
    mailer_host:       127.0.0.1
    mailer_user:       ~
    mailer_password:   ~

    # A secret key that's used to generate certain security-related tokens
    secret:            ThisTokenIsNotSoSecretChangeIt

    database_slave1_host: 127.0.0.1
    database_slave1_port: ~
    database_slave1_name: symfony
    database_slave1_user: root
    database_slave1_password: root

我已阅读并遵循gitlab网站的说明。也许我的错误很明显,但是我看不到。

tmt

当您使用在另一个容器中运行的MySQL时,必须使用其主机名,而不是127.0.0.1正确的数据库主机应为“ mysql”GitLab文档的其中一个部分对此进行了介绍:

MySQL的服务容器可以在主机名mysql下访问。因此,为了访问数据库服务,您必须连接到名为mysql的主机,而不是套接字或localhost。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PHP连接失败:SQLSTATE [HY000] [2002]连接被拒绝

Laravel SQLSTATE [HY000] [2002]连接被拒绝| 锻造 AWS

Laravel Nova + Homestead SQLSTATE [HY000] [2002]连接被拒绝

RDS Laravel SQLSTATE[HY000] [2002] 连接被拒绝

Laravel 7 SQLSTATE [HY000] [2002]连接被拒绝

Laravel:SQLSTATE [HY000] [2002]连接被拒绝

PHP PDO:SQLSTATE [HY000] [2002]连接被拒绝

Laravel SQLSTATE [HY000] [2002]连接被拒绝,但修改过

PHP + MYSQL + Laravel - “SQLSTATE[HY000] [2002] 连接被拒绝”

SQLSTATE[HY000] [2002] 连接被拒绝 Laravel 8

Symfony 2:[PDOException] SQLSTATE [HY000] [2002]连接被拒绝的实体生成器

Symfony SQLSTATE [HY000] [2002]与1and1服务器的连接被拒绝

Symfony4 / Docker:SQLSTATE [HY000] [2002]连接被拒绝

SQLSTATE [HY000] [1040]连接太多

Symfony 5:为什么我会收到这个错误?SQLSTATE[HY000] [2002] 连接被拒绝

Laravel 5.7 SQLSTATE[HY000] [2002] 无法建立连接

SQLSTATE[HY000] [2002] 无法建立连接

托管项目时的连接问题:SQLSTATE[HY000] [2002] 连接被拒绝

SQLSTATE [HY000] [2002]在laravel和docker设置中拒绝连接

SQLSTATE [HY000] [2002]在Docker中运行多个laravel项目时,连接被拒绝

在带有MAMP的Mac上出现“ db:SQLSTATE [HY000] [2002]连接被拒绝”错误

Laravel:SQLSTATE HY000 2002无法建立连接,因为目标机器主动拒绝了它

SQLSTATE [HY000] [2002] Laravel宅基地内的连接被拒绝

61SQLSTATE[HY000] [2002] Docker 容器 PHP/Apache 中的连接被拒绝

php artisan migration命令错误:Illuminate \ Database \ QueryException:SQLSTATE [HY000] [2002]连接被拒绝

驱动程序中发生异常:SQLSTATE [HY000] [2002]连接被拒绝

如何修复 Laravel 中的“SQLSTATE[HY000] [2002] 连接被拒绝”错误(docker 中的工匠迁移)

Xampp Linux:PDOException:SQLSTATE [HY000] [2002]在lock_may_be_available()错误中拒绝连接

SQLSTATE [HY000] [2002]仅在浏览器中拒绝连接