加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:56:05 所属栏目:PHP教程 来源:网络整理
导读:每次有人推送代码时,我都会使用gitlab运行单元测试.我在作曲家安装期间遇到此错误. IncenteevParameterHandlerScriptHandler::buildParametersCreating the "app/config/parameters.yml" file SensioBundleDistributionBundleComposerScriptHandler::b
每次有人推送代码时,我都会使用gitlab运行单元测试.我在作曲家安装期间遇到此错误.

> IncenteevParameterHandlerScriptHandler::buildParameters
Creating the "app/config/parameters.yml" file
> SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap
> SensioBundleDistributionBundleComposerScriptHandler::clearCache


  [DoctrineDBALExceptionConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  



  [DoctrineDBALDriverPDOException]        
  SQLSTATE[HY000] [2002] Connection refused  



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


Script SensioBundleDistributionBundleComposerScriptHandler::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 *ntStrictHostKeyChecking nonn" > ~/.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网站的说明.也许我的错误是显而易见的,但我看不到它.

解决方法

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

The service container for MySQL will be accessible under the hostname mysql. So,in order to access your database service you have to connect to the host named mysql instead of a socket or localhost.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读