php – Gitlab CI Symfony:SQLSTATE [HY000] [2002] Connection拒绝了

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Gitlab CI Symfony:SQLSTATE [HY000] [2002] Connection拒绝了脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
每次有人推送代码时,我都会使用gITlab运行单元测试.我在作曲家安装期间遇到此错误. @H_403_7@

@H_403_7@

> 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
@H_403_7@这是我的配置:

@H_403_7@.gitlab-ci.yml文件

@H_403_7@

# 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 ]] &amp;& 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/
@H_403_7@parameters.yml.dist

@H_403_7@

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
@H_403_7@我已阅读并遵循gitlab网站的说明.也许我的错误是显而易见的,但我看不到它.

解决方法

当您使用在另一个容器中运行的MysqL时,您必须使用其主机名,而不是127.0.0.1.正确的数据库主机应该是“MysqL”.这包含在G000Lab的 one of the sections文档中: @H_403_7@

@H_403_7@

脚本宝典总结

以上是脚本宝典为你收集整理的php – Gitlab CI Symfony:SQLSTATE [HY000] [2002] Connection拒绝了全部内容,希望文章能够帮你解决php – Gitlab CI Symfony:SQLSTATE [HY000] [2002] Connection拒绝了所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。