When installing the simple bootstrap example app on osx Sierra (10.12.4) I received an error when trying to run ‘rails server’ after running bundle install when adding mysql2 as a Gemfile entry:
> rails s /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'mysql2'. (Bundler::GemRequireError) Gem Load Error is: Incorrect MySQL client library version! This gem was compiled for 5.6.19 but the client library is 5.7.18. Backtrace for gem load error is: /Users/$username/.rvm/gems/ruby-2.2.3/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler.rb:107:in `require' /Users/$username/consulting/bootstrap/simple_form-bootstrap/config/application.rb:7:in ` ' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:79:in `require' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:79:in `block in server' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:76:in `tap' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:76:in `server' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:40:in `run_command!' /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands.rb:17:in ` ' bin/rails:4:in `require' bin/rails:4:in ` ' Bundler Error Backtrace: from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:90:in `block (2 levels) in require' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in require' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/bundler-1.14.6/lib/bundler.rb:107:in `require' from /Users/$username/consulting/bootstrap/simple_form-bootstrap/config/application.rb:7:in ` ' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:79:in `require' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:79:in `block in server' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:76:in `tap' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:76:in `server' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:40:in `run_command!' from /Users/$username/.rvm/gems/ruby-2.2.3/gems/railties-4.1.16/lib/rails/commands.rb:17:in ` ' from bin/rails:4:in `require' from bin/rails:4:in ` '
It looks like there is a conflict between the mysql version installed via brew and the one installed via the DMG file downloaded from mysql.
I was able to resolve this issue by explicitly defining the mysql_config from the mysql installed via brew, ie:
ARCHFLAGS="-arch x86_64" gem install mysql2 -v 0.3.21 -- –with-mysql-config=/usr/local/bin/mysql_config bundle install
Note that it is important to install the version of the mysql2 gem that would be installed via bundle install.
Leave a Reply