Ruby 关于 Rails 4.1.8 Gem::LoadError 对于 mysql2 gem

Ruby on Rails 4.1.8 Gem::LoadError for mysql2 gem

我选择了一个用 Ruby 2.1.3Rails 4.1.8 编写的 4 年前的项目。

很少有 gem 版本化,但我已经按照多个其他线程中的建议通过安装 mysql2 0.3.20 设法在本地获取项目 运行。这样做需要我(在 MacOS 上)用 brew install mysql@57brew install openssl@10.

降级 openssl 和 mysql

然后我可以通过将正确的库传递给它来安装 mysql2gem install mysql2 -v 0.3.20 -- --with-mysql-config=/usr/local/opt/mysql@5.7/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl@1.0/lib --with-cppflags=-I/usr/local/opt/openssl@1.0/include

一切都在本地工作,一切都很好。

我正在尝试在 Debian 实例上使用 Dokku 部署这个项目。这是从推送到 dokku master 的读数,包括启动 Rails 服务器时抛出的错误:

Dev@Jordans-MacBook-Pro ~/runritewinDB2020 (master) $ git push dokku master
Enumerating objects: 1608, done.
Counting objects: 100% (1608/1608), done.
Delta compression using up to 4 threads
Compressing objects: 100% (975/975), done.
Writing objects: 100% (1608/1608), 14.90 MiB | 1.19 MiB/s, done.
Total 1608 (delta 611), reused 1520 (delta 554)
remote: Resolving deltas: 100% (611/611), done.
-----> Cleaning up...
-----> Building runrite from dockerfile...
remote: build context to Docker daemon  51.88MB
Step 1/17 : FROM ruby:2.1.3
 ---> e1f10119c75a
Step 2/17 : RUN apt-get install -y libpq-dev
 ---> Using cache
 ---> 18e44db81b01
Step 3/17 : RUN apt-get install -y libxml2-dev libxslt1-dev
 ---> Using cache
 ---> b753197bec2f
Step 4/17 : ENV RAILS_ENV production
 ---> Using cache
 ---> fe632f7c4b4f
Step 5/17 : ENV RACK_ENV production
 ---> Using cache
 ---> ebeb94b2a120
Step 6/17 : ENV RACK production
 ---> Using cache
 ---> 98942a7c066f
Step 7/17 : ENV DB_URL mysql://mysql:f7a080fdf10779b0@dokku-mysql-runrite-production:3306/runrite_production
 ---> Using cache
 ---> 0feff73f3952
Step 8/17 : ENV APP_HOME /myapp
 ---> Using cache
 ---> 472864c3692a
Step 9/17 : RUN mkdir $APP_HOME
 ---> Using cache
 ---> 8cf938f4771b
Step 10/17 : WORKDIR $APP_HOME
 ---> Using cache
 ---> 83c835ef8ba6
Step 11/17 : ADD Gemfile* $APP_HOME/
 ---> 687cafb12ca9
Step 12/17 : RUN bundle install
 ---> Running in df7a7d1b74a3
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching source index from https://rubygems.org/
Fetching git://github.com/activerecord-hackery/polyamorous.git
Fetching git://github.com/activeadmin/activeadmin.git
Fetching https://github.com/stripe/stripe-ruby
Installing rake 10.4.2
Installing CFPropertyList 2.2.8
Installing i18n 0.7.0
Installing json 1.8.3
Installing minitest 5.8.0
Installing thread_safe 0.3.5
Installing tzinfo 1.2.2
Installing activesupport 4.1.8
Installing builder 3.2.2
Installing erubis 2.7.0
Installing actionview 4.1.8
Installing rack 1.5.5
Installing rack-test 0.6.3
Installing actionpack 4.1.8
Installing mime-types 2.6.1
Installing mail 2.6.3
Installing actionmailer 4.1.8
Installing activemodel 4.1.8
Installing active_model_serializers 0.9.0
Installing arbre 1.0.3
Installing sass 3.2.19
Installing thor 0.19.1
Installing bourbon 3.2.4
Installing coffee-script-source 1.9.1.1
Installing execjs 2.6.0
Installing coffee-script 2.4.1
Installing railties 4.1.8
Installing coffee-rails 4.0.1
Installing formtastic 3.1.3
Installing formtastic_i18n 0.4.1
Installing has_scope 0.6.0
Installing responders 1.1.2
Installing inherited_resources 1.6.0
Installing jquery-rails 3.1.3
Installing jquery-ui-rails 5.0.5
Installing kaminari 0.16.3
Installing arel 5.0.1.20140414130214
Installing activerecord 4.1.8
Using bundler 1.7.4
Installing hike 1.2.3
Installing multi_json 1.11.2
Installing tilt 1.4.1
Installing sprockets 2.12.4
Installing sprockets-rails 2.3.2
Installing rails 4.1.8
Using polyamorous 1.3.3 from git://github.com/activerecord-hackery/polyamorous.git (at master)
Installing ransack 1.7.0
Installing sass-rails 4.0.5
Using activeadmin 1.0.0.pre1 from git://github.com/activeadmin/activeadmin.git (at master)
Installing addressable 2.3.6
Installing multipart-post 2.0.0
Installing avocado-docs 3.0.7
Installing mini_portile 0.6.0
Installing nokogiri 1.6.3.1
Installing aws-sdk-v1 1.56.0
Installing aws-sdk 1.56.0
Installing bcrypt 3.1.7
Installing coderay 1.1.0
Installing better_errors 2.0.0
Installing debug_inspector 0.0.2
Installing binding_of_caller 0.7.2
Installing columnize 0.8.9
Installing debugger-linecache 1.2.0
Installing slop 3.6.0
Installing byebug 3.5.1
Installing cancancan 1.9.2
Installing colorize 0.7.7
Installing net-ssh 2.9.2
Installing net-scp 1.2.1
Installing sshkit 1.7.1
Installing capistrano 3.4.0
Installing capistrano-bundler 1.1.3
Installing capistrano-rails 1.1.2
Installing capistrano-rbenv 2.0.2
Installing capistrano3-unicorn 0.2.1
Installing xpath 2.0.0
Installing capybara 2.4.4
Installing carrierwave 0.10.0
Installing streamio-ffmpeg 1.0.0
Installing carrierwave-video 0.5.6
Installing hitimes 1.2.2
Installing timers 4.0.1
Installing celluloid 0.16.0
Installing chartkick 1.3.2
Installing commonjs 0.2.7
Installing safe_yaml 1.0.4
Installing crack 0.4.2
Installing css_parser 1.3.7
Installing database_cleaner 1.3.0
Installing orm_adapter 0.5.0
Installing warden 1.2.3
Installing devise 3.4.0
Installing devise_invitable 1.4.1
Installing interception 0.5
Installing did_you_mean 0.9.6
Installing diff-lcs 1.2.5
Installing docile 1.1.5
Installing unf_ext 0.0.7.1
Installing unf 0.1.4
Installing domain_name 0.5.24
Installing launchy 2.4.2
Installing email_spec 1.6.0
Installing enumerize 0.9.0
Installing exception_notification 4.1.1
Installing excon 0.42.1
Installing fabrication 2.11.3
Installing faker 1.4.3
Installing faraday 0.9.0
Installing faraday_middleware 0.9.1
Installing ffi 1.9.6
Installing figaro 1.0.0
Installing fission 0.5.0
Installing formatador 0.2.5
Installing fog-core 1.27.2
Installing fog-xml 0.1.1
Installing fog-atmos 0.1.0
Installing fog-json 1.0.0
Installing inflecto 0.0.2
Installing fog-brightbox 0.7.1
Installing fog-ecloud 0.0.2
Installing fog-profitbricks 0.0.1
Installing fog-radosgw 0.0.3
Installing fog-sakuracloud 0.1.1
Installing fog-softlayer 0.3.25
Installing fog-storm_on_demand 0.1.0
Installing fog-terremark 0.0.3
Installing fog-vmfusion 0.0.1
Installing fog-voxel 0.0.2
Installing ipaddress 0.8.0
Installing fog 1.26.0
Installing font-awesome-rails 4.2.0.0
Installing rb-fsevent 0.9.4
Installing rb-inotify 0.9.5
Installing listen 2.7.11
Installing lumberjack 1.0.9
Installing method_source 0.8.2
Installing pry 0.10.1
Installing guard 2.6.1
Installing guard-bundler 2.0.0
Installing guard-rails 0.6.0
Installing rspec-support 3.1.2
Installing rspec-core 3.1.7
Installing rspec-expectations 3.1.2
Installing rspec-mocks 3.1.3
Installing rspec 3.1.0
Installing guard-rspec 4.3.1
Installing hashie 3.3.1
Installing htmlentities 4.3.4
Installing http-cookie 1.0.2
Installing multi_xml 0.5.5
Installing httparty 0.13.1
Installing jbuilder 2.2.3
Installing jwt 1.0.0
Installing kgio 2.9.2
Installing less 2.6.0
Installing less-rails 2.6.0
Installing libv8 3.16.14.7
Installing mysql2 0.3.20
Installing netrc 0.10.3
Installing oauth 0.4.7
Installing oauth2 1.0.0
Installing omniauth 1.2.2
Installing omniauth-oauth2 1.2.0
Installing omniauth-facebook 2.0.0
Installing omniauth-oauth 1.0.1
Installing omniauth-twitter 1.1.0
Installing owlcarousel-rails 1.1.3.3
Installing paper_trail 3.0.6
Installing premailer 1.8.6
Installing premailer-rails 1.8.2
Installing pry-byebug 2.0.0
Installing pry-rails 0.3.2
Installing puma 2.13.3
Installing pundit 0.3.0
Installing pushmeup 0.3.0
Installing rails-observers 0.1.2
Installing raindrops 0.13.0
Installing rb-fchange 0.0.6
Installing ref 1.0.5
Installing rest-client 1.8.0
Installing rmagick 2.15.0
Installing rspec-rails 3.1.0
Installing shoulda-context 1.2.1
Installing shoulda-matchers 2.7.0
Installing shoulda 3.5.0
Installing simple_form 3.1.0
Installing simplecov-html 0.8.0
Installing simplecov 0.9.1
Installing spring 1.1.3
Using stripe 1.26.0 from https://github.com/stripe/stripe-ruby (at master)
Installing therubyracer 0.12.1
Installing twitter-bootstrap-rails 3.2.0
Installing uglifier 2.5.3
Installing unicorn 4.8.3
Installing webmock 1.19.0
Installing yarjuf 2.0.0
Your bundle is complete!
It was installed into /usr/local/bundle
Post-install message from capistrano:
Capistrano 3.1 has some breaking changes. Please check the CHANGELOG: #Edited for shortened URL

If you're upgrading Capistrano from 2.x, we recommend to read the upgrade guide: # Remove shortened URL

The `deploy:restart` hook for passenger applications is now in a separate gem called capistrano-passenger.  Just add it to your Gemfile and require it in your Capfile.
Post-install message from httparty:
When you HTTParty, you must party hard!
Post-install message from twitter-bootstrap-rails:
Important: You may need to add a javascript runtime to your Gemfile in order for bootstrap's LESS files to compile to CSS.

**********************************************

ExecJS supports these runtimes:

therubyracer - Google V8 embedded within Ruby

therubyrhino - Mozilla Rhino embedded within JRuby

Node.js

Apple JavaScriptCore - Included with Mac OS X

Microsoft Windows Script Host (JScript)

**********************************************
Removing intermediate container df7a7d1b74a3
 ---> cab4f5704fc6
Step 13/17 : ADD . $APP_HOME
 ---> ffda2dba11f3
Step 14/17 : RUN bundle exec rails server
 ---> Running in 3079acec1dac
=> Booting Puma
=> Rails 4.1.8 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/usr/local/bundle/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:190:in `rescue in spec': Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
remote: from /usr/local/bundle/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:187:in `spec'
remote: from /usr/local/bundle/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:50:in `establish_connection'
remote: from /usr/local/bundle/gems/activerecord-4.1.8/lib/active_record/railtie.rb:129:in `block (2 levels) in <class:Railtie>'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `each'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
remote: from /usr/local/bundle/gems/activerecord-4.1.8/lib/active_record/railtie.rb:118:in `block in <class:Railtie>'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `each'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `call'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
remote: from /usr/local/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
remote: from /myapp/config/environment.rb:5:in `<top (required)>'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
remote: from /usr/local/bundle/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
remote: from /myapp/config.ru:3:in `block in <main>'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
remote: from /myapp/config.ru:in `new'
remote: from /myapp/config.ru:in `<main>'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/builder.rb:49:in `eval'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/builder.rb:49:in `new_from_string'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/builder.rb:40:in `parse_file'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/server.rb:277:in `build_app_and_options_from_config'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/server.rb:199:in `app'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/server.rb:50:in `app'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/server.rb:314:in `wrapped_app'
remote: from /usr/local/bundle/gems/rack-1.5.5/lib/rack/server.rb:250:in `start'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/server.rb:69:in `start'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in server'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
remote: from /usr/local/bundle/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
remote: from bin/rails:4:in `require'
remote: from bin/rails:4:in `<main>'
remote: The command '/bin/sh -c bundle exec rails server' returned a non-zero code: 1

Docker 文件:

FROM ruby:2.1.3

RUN apt-get install -y libpq-dev

RUN apt-get install -y libxml2-dev libxslt1-dev

ENV RAILS_ENV production
ENV RACK_ENV production
ENV RACK production
ENV DB_URL mysql://mysql:f7a080fdf10779b0@dokku-mysql-runrite-production:3306/runrite_production

# for a JS runtime
RUN apt-get install -y nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
RUN bundle install

ADD . $APP_HOME

RUN bundle exec rails server

database.yml:

development:
  adapter: mysql2
  database: runrite-web_development
  username: root
  password:
  host: localhost
  socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  database: db/runrite-web_test.sql
  username: root
  password:
  host: localhost
  socket: /tmp/mysql.sock
  timeout: 10000

production: &production
  adapter: mysql2
  encoding: utf8mb4
  charset: utf8mb4
  collation: utf8mb4_unicode_ci
  port: 3306
  database: runrite_production
  url: <%= ENV['DB_URL'] %>
  pool: 25

staging:
  <<: *production

宝石文件:

source 'https://rubygems.org'
ruby '2.1.3'

# TODO: put versions on most of these gems

# Core
gem 'rails', '4.1.8'
gem 'mysql2', '0.3.20'
# gem 'mysql'
# Deployment
gem 'capistrano', '~> 3.4.0', require: false
gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano-rails', '~> 1.1', require: false
gem 'capistrano-bundler', '~> 1.1', require: false
gem 'capistrano3-unicorn', require: false

gem "active_model_serializers"
gem "activeadmin", github: 'activeadmin'
gem "avocado-docs"
gem "aws-sdk"
# gem 'aws-healthcheck'
gem "cancancan"
gem "carrierwave"
gem "carrierwave-video"
gem "devise"
gem "devise_invitable"
gem 'enumerize'
gem "faraday"
gem "faraday_middleware"
gem 'fog'
gem 'font-awesome-rails'
gem "has_scope"
gem 'rmagick'
# gem 'mini_magick'
# gem 'imagemagick-binaries'
gem "omniauth"
gem "omniauth-facebook"
gem "omniauth-twitter"
gem "paper_trail"
gem "polyamorous", github: "activerecord-hackery/polyamorous"
gem "pundit"
gem "pushmeup"
gem "rails-observers"
gem "responders"
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
gem 'coffee-rails', '~> 4.0.0'
gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'sass-rails', '~> 4.0.3'
gem 'spring', group: :development
gem 'simple_form'
# gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'unicorn'
gem 'yarjuf'
gem 'owlcarousel-rails'
gem "chartkick"
gem 'premailer-rails'
gem 'nokogiri'

# E-Commerce
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'

group :development, :test do
  gem "rspec-rails"
  gem 'pry-rails'
  gem 'pry-byebug'
  gem 'shoulda'
  gem 'did_you_mean', '~> 0.9.4'
  gem "guard"
  gem "guard-rspec"
end

group :test do
  gem "capybara"
  gem "fabrication"
  gem "database_cleaner"
  gem "email_spec"
  gem 'simplecov', require: false
  gem 'webmock'
  # gem 'capybara-webkit'
  gem "faker"
end

group :development do
  gem "puma", '~> 2.13.3'
  gem "better_errors"
  gem "binding_of_caller"
  gem "guard-bundler"
  gem "guard-rails"
  gem "rb-fchange", require: false
  gem "rb-fsevent", require: false
  gem "rb-inotify", require: false
end

group :production do
  # gem 'logglier', '~> 0.2.11'                    # sending logs to loggly.com
  # gem 'lograge',  '~> 0.3.4'                     # abbreviated rails logs
  gem 'exception_notification', '~> 4.1.1'       # notification of exceptions via email
end

# gem 'elbas', github: 'lserman/capistrano-elbas'

Debian 实例信息:

Static hostname: debian-1cpu-1gb-us-chi1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 0072a07a9c1349898ba2e35eb78cd8d2
           Boot ID: bfb5d8b9d8cf42d4b766b5089a926016
    Virtualization: kvm
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.19.0-9-amd64
      Architecture: x86-64

OpenSSL 版本:

OpenSSL 1.1.1d  10 Sep 2019

Dokku MYSQL 插件 MYSQL 版本:

5.7.28

我想我需要弄清楚如何在 debian 实例上使用正确版本的 openSSL 构建 mysql2 gem 但我有点不知所措我会怎么做。 mysql2 gem 安装在本地失败,直到我使用顶部提到的可选参数安装它。 mysql2 gem 版本在 debian 实例上安装正常。任何帮助将不胜感激。

我想我明白发生了什么。在您的 Dockerfile 中,将 DB_URL 从:mysql:// 更改为 mysql2://

您正在加载 mysql2 gem,但向 ActiveRecord 表明您想要通过 mysql gem.

使用连接