舊專案環境安裝問題,mysql2跟rails不相容?


#1

使用電腦mac os mojave
專案rails (4.0.0)

mysql2 目前試過0.5.2 / 0.4.10 / 0.3.16 /0.3.20 / 0.3.21

0.5.2 / 0.4.10都可以安裝,但是開啟rails server會出現錯誤
Specified ‘mysql2’ for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile. (Gem::LoadError)

0.3.x則是連安裝都無法


#2

抱歉 … 我一直認為我有回 Orz" 結果一直躺在草稿內,以下是原文

===========

嘛,下次貼圖注意一點,否則人家都知道 … 一些訊息哈哈

首先,mysql2 有 C 語言編譯的部分,需要 libmysqlclient 的支援,osx 下應該類似

brew install mysql

應該就會幫你裝好 server & client 裡面就有包 libmysqlclient 了,至於其他,你的問題應該是 Gemfile 內的 mysql2 版本過低 … 你應該把你的 Gemfile 貼上來才對?或是直接強至指定版本類似

gem 'mysql2', '~> 0.4.10'

這樣的格式如何?


#3

這篇大概知道原因了,但 … 我沒辦法修正,大概描述幾點

首先,mysql2 gem 早期版本只支援 mysql5.5 ~ 5.6 的樣子,5.7 之後應該就會開始噴死,因為會編譯不過,且 macOS 的 xcode 也都有升級,雖然 brew 可以把 mysql 裝到 5.5 版,但仍可能會編譯不過,而現在 brew 預設裝的已經是 8.x 了 … 有趣的是最新的 mysql2 gem 0.5 後新舊都編譯得過,但當年的 rails spec 有寫死 mysql2 gem 的版本必須為 0.3,但 Gemfile 內卻沒限制版本,會造成 rails 開不起來然後甚至和你說沒有 mysql2 gem … 有的沒的

所以以上,雖然我可以帶你走很多 dirty 的路,類似以下,但最後還是失敗的

gem uninstall mysql2 --all # 移除所有 mysql2 gem
brew remove mysql # 移除目前 mysql
rm -rf /usr/local/var/mysql* #清空舊有的 data 資料夾,否則 mysql 會跑不起來(刪庫跑路)
brew install mysql@5.5 #安裝舊版的 mysql
brew link mysql@5.5 --force #強制 link
# 重開機後重下面開始做
brew services start mysql@5.5 #開啟 server
gem i mysql2 -v=0.3.10 #嘗試編譯
# fail

我可能可以修好,但 … 單純建議,你重新嘗試跑在 linux 上面(前提一樣,使用舊版本的 mysql 等等),或把你的專案更新成新版如何?因為對我而言這些應該都 out of date & 使用舊版會增加安全性危險之類的


#4

最近再做一個rails的交易所的時候也碰到類似樓主的問題,所以借串發問
不一樣的是在rake db:setup時出錯
系統是ubuntu16.04
ruby 2.3.1
rails 4.0.12
mysql2 0.3.15錯誤是

NameError: uninitialized constant Mysql2::Client::SECURE_CONNECTION

mysql2 0.3.10 在bundle install出錯

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

其它mysql2 版本 0.3.18, 0.3.20, 0.4.0, 0.4.10 會出現這篇類似的問題

/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:in non_string_configuration!' : WARNING: Use strings for Figaro configuration. 60 was converted to "60". (StructuredWarnings::StandardWarning) /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:innon_string_configuration!’ : WARNING: Use strings for Figaro configuration. 587 was converted to “587”. (StructuredWarnings::StandardWarning)
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:in non_string_configuration!' : WARNING: Use strings for Figaro configuration. 8080 was converted to "8080". (StructuredWarnings::StandardWarning) /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:innon_string_configuration!’ : WARNING: Use strings for Figaro configuration. 519786 was converted to “519786”. (StructuredWarnings::StandardWarning)
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:in non_string_configuration!' : WARNING: Use strings for Figaro configuration. 80 was converted to "80". (StructuredWarnings::StandardWarning) /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:innon_string_configuration!’ : WARNING: Use strings for Figaro configuration. 80 was converted to “80”. (StructuredWarnings::StandardWarning)
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:in non_string_configuration!' : WARNING: Use strings for Figaro configuration. 443 was converted to "443". (StructuredWarnings::StandardWarning) /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/figaro-1.1.1/lib/figaro/application.rb:84:innon_string_configuration!’ : WARNING: Use strings for Figaro configuration. true was converted to “true”. (StructuredWarnings::StandardWarning)
Specified ‘mysql2’ for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile.
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:58:in rescue in resolve_hash_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:55:inresolve_hash_connection’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:34:in spec' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_handling.rb:39:inestablish_connection’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/mysql_database_tasks.rb:8:in establish_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/mysql_database_tasks.rb:15:increate’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:73:in create' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:87:inblock in create_current’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:183:in block in each_current_configuration' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:182:ineach’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:182:in each_current_configuration' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:86:increate_current’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/railties/databases.rake:20:in block (2 levels) in <top (required)>' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:273:inblock in execute’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:273:in each' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:273:inexecute’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:214:in block in invoke_with_call_chain' /home/gic/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:194:in invoke_with_call_chain' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:238:inblock in invoke_prerequisites’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:236:in each' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:236:ininvoke_prerequisites’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:213:in block in invoke_with_call_chain' /home/gic/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:194:in invoke_with_call_chain' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:238:inblock in invoke_prerequisites’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:236:in each' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:236:ininvoke_prerequisites’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:213:in block in invoke_with_call_chain' /home/gic/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:194:in invoke_with_call_chain' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/task.rb:183:ininvoke’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:160:in invoke_task' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:116:inblock (2 levels) in top_level’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:116:in each' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:116:inblock in top_level’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:125:in run_with_threads' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:110:intop_level’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:83:in block in run' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:186:instandard_exception_handling’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/lib/rake/application.rb:80:in run' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/exe/rake:27:in<top (required)>’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/bin/rake:23:in load' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/bin/rake:23:in<top (required)>’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in load' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:inkernel_load’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:28:in run' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli.rb:463:inexec’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:ininvoke_command’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor.rb:387:in dispatch' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli.rb:27:indispatch’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in start' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/cli.rb:18:instart’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/exe/bundle:30:in block in <top (required)>' /home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/lib/bundler/friendly_errors.rb:124:inwith_friendly_errors’
/home/gic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.1/exe/bundle:22:in <top (required)>' /home/gic/.rbenv/versions/2.3.1/bin/bundle:23:inload’
/home/gic/.rbenv/versions/2.3.1/bin/bundle:23:in `’

Couldn’t create database for {“adapter”=>“mysql2”, “encoding”=>“utf8”, “database”=>“peatio_production”, “username”=>“root”, “password”=>“gicgicgic”, “pool”=>10, “reconnect”=>true}
rake aborted!
Gem::LoadError: Specified ‘mysql2’ for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile.
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:58:in rescue in resolve_hash_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:55:inresolve_hash_connection’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:46:in resolve_string_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:32:inspec’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_handling.rb:39:in establish_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:89:increate_current’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/railties/databases.rake:20:in block (2 levels) in <top (required)>' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/exe/rake:27:in<top (required)>’
/home/gic/.rbenv/versions/2.3.1/bin/bundle:23:in load' /home/gic/.rbenv/versions/2.3.1/bin/bundle:23:in

Caused by:
Gem::LoadError: can’t activate mysql2 (~> 0.3.10), already activated mysql2-0.4.10. Make sure all dependencies are added to Gemfile.
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in <top (required)>' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:229:inrequire’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:229:in block in require' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:214:inload_dependency’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activesupport-4.0.13/lib/active_support/dependencies.rb:229:in require' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:56:inresolve_hash_connection’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:46:in resolve_string_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_adapters/connection_specification.rb:32:inspec’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/connection_handling.rb:39:in establish_connection' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/tasks/database_tasks.rb:89:increate_current’
/home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/activerecord-4.0.13/lib/active_record/railties/databases.rake:20:in block (2 levels) in <top (required)>' /home/gic/code/exchange/vendor/bundle/ruby/2.3.0/gems/rake-12.3.2/exe/rake:27:in<top (required)>’
/home/gic/.rbenv/versions/2.3.1/bin/bundle:23:in load' /home/gic/.rbenv/versions/2.3.1/bin/bundle:23:in'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
(See full trace by running task with --trace)

然後是參考這篇的解法

gic@ubuntu:~/code/exchange$ gem uninstall mysql2 --all
Successfully uninstalled mysql2-0.4.10
gic@ubuntu:~/code/exchange$ sudo apt-get remove mysql
[sudo] password for gic:
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package mysql
gic@ubuntu:~/code/exchange$ sudo apt-get install mysql@5.5
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package mysql@5.5
E: Couldn’t find any package by glob 'mysql@5.5’
E: Couldn’t find any package by regex ‘mysql@5.5’

下面是gemfile

source ‘https://rubygems.org

gem ‘rails’, '~> 4.0.12’
gem ‘rails-i18n’

gem 'mysql2’
gem 'daemons-rails’
gem ‘redis-rails’

gem 'rotp’
gem 'json’
gem 'jbuilder’
gem ‘bcrypt-ruby’, ‘~> 3.1.2’

gem ‘doorkeeper’, '~> 1.4.1’
gem ‘omniauth’, '~> 1.2.1’
gem ‘omniauth-identity’, ‘~> 1.1.1’

gem 'figaro’
gem ‘hashie’

gem ‘aasm’, '~> 3.4.0’
gem ‘amqp’, '~> 1.3.0’
gem ‘bunny’, '~> 1.2.1’
gem 'cancancan’
gem 'enumerize’
gem 'datagrid’
gem 'acts-as-taggable-on’
gem 'kaminari’
gem 'paranoid2’
gem 'active_hash’
gem 'http_accept_language’
gem “globalize”, "~> 4.0.0"
gem ‘paper_trail’, '~> 3.0.1’
gem 'rails-observers’
gem ‘country_select’, ‘~> 2.1.0’

gem ‘gon’, '~> 5.2.0’
gem 'pusher’
gem ‘eventmachine’, '~> 1.0.4’
gem ‘em-websocket’, ‘~> 0.5.1’

gem ‘simple_form’, '~> 3.1.0’
gem 'slim-rails’
gem 'sass-rails’
gem 'coffee-rails’
gem 'uglifier’
gem "jquery-rails"
gem "angularjs-rails"
gem ‘bootstrap-sass’, '~> 3.2.0.2’
gem 'bootstrap-wysihtml5-rails’
gem 'font-awesome-sass’
gem 'bourbon’
gem 'momentjs-rails’
gem 'eco’
gem ‘browser’, '~> 0.8.0’
gem 'rbtree’
gem ‘whenever’, '~> 0.9.2’
gem ‘grape’, '~> 0.7.0’
gem ‘grape-entity’, '~> 0.4.2’
gem ‘grape-swagger’, '~> 0.7.2’
gem ‘rack-attack’, '~> 3.0.0’
gem 'easy_table’
gem ‘faraday’, '~> 0.12’
gem ‘phonelib’, '~> 0.3.5’
gem ‘twilio-ruby’, '~> 3.11’
gem ‘unread’, github: 'Apollo-IT/unread’
gem ‘carrierwave’, '~> 0.10.0’
gem ‘simple_captcha2’, require: 'simple_captcha’
gem ‘rest-client’, '~> 1.6.8’
gem ‘memoist’, '~> 0.16’
gem ‘method-not-implemented’, '~> 1.0’
gem ‘passgen’, ‘~> 1.0’
#gem ‘digest-sha3’, '~> 1.1’
gem ‘digest-sha3-patched’, ‘~> 1.1’, '>= 1.1.1’
gem ‘bluecloth’, '~> 2.2’
gem ‘rake-compiler’, '~> 0.8.3’
gem ‘yard’, ‘~> 0.9.16’

group :development, :test do
gem 'factory_girl_rails’
gem ‘faker’, '~> 1.4.3’
gem 'mina’
gem ‘mina-slack’, github: 'Apollo-IT/mina-slack’
gem 'meta_request’
gem 'better_errors’
gem ‘binding_of_caller’
#gem 'pry-rails’
gem 'quiet_assets’
gem 'mails_viewer’
gem 'timecop’
gem 'dotenv-rails’
gem ‘rspec-rails’
#gem 'byebug’
end

group :test do
gem 'database_cleaner’
gem ‘mocha’, :require => false
gem 'shoulda-matchers’
gem 'capybara’
gem 'launchy’
gem 'selenium-webdriver’
gem ‘poltergeist’

#rspec-rails rely on test-unit if rails version less then 4.1.0
#but test-unit has been removed from ruby core since 2.2.0
gem 'test-unit’
end


#5

首先 …

mysql@5.5

這種用法只能用在 macOS 的 homebrew 上,我想你用的應該是 linux 的 ubuntu 才是對唄 …

你可以先用

$ apt-cache search mysql-server*
mysql-server - MySQL database server (metapackage depending on the latest version)
mysql-server-5.7 - MySQL database server binaries and system database setup
mysql-server-core-5.7 - MySQL database server binaries

這些才是你可以裝的 server 套件才是,但這應該不是你主要的問題,因為 Rails 4 後應該都有支援之後版本才是,但建議指定版本,因為後來應該都會裝到 … mariadb 去,雖然用起來應該沒差

sudo apt-get install mysql-server-5.7 libmysqlclient-dev

且一定要裝後面的那個 libmysqlclient-dev 否則你的 mysql2 gem 應該怎樣都 build 不起來

之後才去安裝 mysql2 gem,應該就不會遇到 Failed to build gem native extension 問題?其實說不定也和 mysql2 / mysql-server 版本無關才是

再來 … 你剛說了 “交易所” 所以去對了一下你給的 Gemfile ,這份是 貔貅 peatio 對唄,他們那份做了一狗票的特化非常難改且難用,滿滿的 mixin 和繼承,且過度信賴 RabbitMQ,還有一票有趣的 bug,事實上我不認為那架構可以跑成交易所,因為完全不可靠,所以可以的話就別用了唄||||,奉勸一句:別人踩過的坑沒道理你不會踩到,只是早晚的問題而已,類似技術債、交易演算法的一些陷阱、安全性議題之類的||||

不過另外一方面,真的要用的話也用別的版本,該專案超過四年沒更新了,且一大票相依的 gem 都不知道更新到哪裡去了,其實 Github 上面還是有些好心人在幫忙 peatio 做 update,不過是 fork 出去的版本就是,所以盡量找一個最新的 fork 才下來實作,說不定有問題發給那個 fork 專案的人,還會可以有討論空間之類的(不過這邊也是以 github 的生態而言,實際我不太能確定就是)