mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

cannot load such file -- mysql2/mysql2 (LoadError)

Open Cristopheer96 opened this issue 2 years ago • 5 comments

Hi everyone I trying run 'rails c' in a project, but I get an unexpected error :S. Thanks in advance. This is my logs => ➜ backend-ror git:(rails) ✗ rails c /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `require': cannot load such file -- mysql2/mysql2 (LoadError) from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `<top (required)>' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:81:in `require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:81:in `block (2 levels) in require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:76:in `each' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:76:in `block in require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:65:in `each' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:65:in `require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler.rb:114:in `require' from /Users/Cristopheer96/code/Cristopheer96/Guudjob/backend-ror/config/application.rb:7:in `<top (required)>' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /Users/Cristopheer96/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from -e:1:in `<main>'

Cristopheer96 avatar May 03 '22 02:05 Cristopheer96

Looks like there might have been a problem installing mysql2. Can you try re-bundling and see if that fixes it?

tenderlove avatar May 03 '22 16:05 tenderlove

I have encountered the same issue after updating the mysql2 gem to 0.5.4. When I try to run rake db:migrate I get the following error rake aborted! LoadError: cannot load such file -- mysql2/mysql2 When I reverted the gem to version 0.5.3 it all works fine.

It looks like the line 36 in the lib/mysql2.rb is the issue, but I'm not 100% sure why.

mireksawicz avatar May 08 '22 08:05 mireksawicz

@mireksawicz are you able to do gem install mysql2 -v 0.5.4? This error is due to the C extension not being built, but you should have seen an error when you installed the gem in the first place.

tenderlove avatar May 10 '22 00:05 tenderlove

Seeing this same behavior on M1 Mac with 0.5.3. Install options: --with-mysql-include=$(brew --prefix [email protected])/include --with-mysql-config=$(brew --prefix [email protected])/bin/mysql_config --with-opt-dir=$(brew --prefix [email protected]) with gem install mysql2 -v 0.5.3

psulightning avatar May 05 '23 17:05 psulightning

So interestingly enough, issue didn't occur with bundler after setting up configuration.

bundle config build.mysql2 --with-mysql-config=$(brew --prefix [email protected])/bin/mysql_config --with-opt-dir=$(brew --prefix [email protected])

psulightning avatar May 05 '23 18:05 psulightning