无法通过套接字'/var/run/mysqld/mysqld.sock Circle Ci / Rails / Mysql连接到本地MySQL服务器

问题描述 投票:0回答:1

我正在尝试为我公司的应用程序创建一个circleci构建。我现在只想做的是建立一个Rails项目,并使用MySQL数据库运行存储库中的测试。现在,当我的circeci尝试构建时,我遇到了followint错误。

#<Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
rake aborted!
failed to execute:
mysqlPlease check the output above for any errors and make sure that `mysql` is installed in your PATH and has proper permissions.

我遵循了中型关节,Circ Ci文档和youtube视频的组合,但是我似乎无法使这种配置有效。我花了很多时间试图找出问题所在,并且可以真正使用一些资深的ci用户来提供帮助。这是我对.circleci/config.yml的最新迭代:

version: 2
jobs:
  build:
    working_directory: ~/app
    docker:
      - image: circleci/ruby:2.6.2
        environment:
          RAILS_ENV: test
          DB_HOST: 127.0.0.1
      - image: circleci/mysql:5.7.28
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
          MYSQL_ROOT_HOST: '%'
          MYSQL_DATABASE: app_test
          MYSQL_USER: root
    steps:
      - checkout

      # Restore bundle cache
      - restore_cache:
          keys:
            - app-rails-{{ checksum "Gemfile.lock" }}
            - app-rails-

      - run:
          name: Get the correct bundler
          command: |
            sudo apt-get install unixodbc-dev
            sudo apt-get -y install mysql-server
            sudo gem uninstall bundler
            sudo rm /usr/local/bin/bundle
            sudo rm /usr/local/bin/bundler
            sudo gem install bundler -v 1.17.3
            mv config/local_env.ci.yml config/local_env.yml
            mv config/database.ci.yml config/database.yml

      # Bundle install dependencies
      - run:
          name: Install dependencies
          command: bundle install

      # Store bundle cache
      - save_cache:
          key: app-rails-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - run:
          name: Database Setup
          command: |
            bundle exec rake db:create
            bundle exec rake db:structure:load
            bundle exec rake db:migrate

      - run:
          name: Run Minitest
          command: rake test

这不应该是一个复杂的构建。我只需要构建我的应用程序和rake test。对于那些已经配置了rails和mysql的人,我的配置看起来有什么不对吗?问题在于,我对于其他有关环境变量的示例感到困惑。例如,我已经看到DB_HOST: localhost MYSQL_HOST: localhost等,然后我在ruby图像或mysql图像中看到了这些变量。当我在circleci文档中阅读一种方式时,我看到了另一个示例,该示例未使用文档中的配置,但是声称它可以工作。此时,我的头在旋转。

显然,我的构建无法正常运行,但据我所知,我认为它应该是正确的。这就是我的database.yml文件中的内容。它仅包含此内容。

test: &TEST
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: app_test
  username: test
  password:

有人可以帮助我,并向我指出我要去哪里了。帮助将不胜感激。谢谢。

mysql ruby-on-rails circleci
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.