Topic: cannot load such file -- mysql2/mysql2

I ran into an issue while upgrading a Rails-Project from Rails 2 t Rails 3.
For simplicity I started a new project from en empty directory and got the same error message.

I did:

rails new . -d mysql
rails server

and got the message

/usr/local/share/gems/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
        from /usr/local/share/gems/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `<top (required)>'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `each'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `block in require'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `each'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `require'
        from /usr/local/share/gems/gems/bundler-1.2.1/lib/bundler.rb:128:in `require'
        from /home/ewi/prog/rails/new/config/application.rb:7:in `<top (required)>'
        from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
        from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
        from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
        from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

Indeed, line 9 of /usr/local/share/gems/gems/mysql2-0.3.11/lib/mysql2.rb reads

require 'mysql2/mysql2'

but there is no file
/usr/local/share/gems/gems/mysql2-0.3.11/lib/mysql2/mysql2.rb
The other required files from this directory exist.

Is this a bug in mysql2? Is there any workaround?

I am using
rails (3.2.8)
mysql2 (0.3.11)
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
mysql  Ver 14.14 Distrib 5.5.27, for Linux (x86_64) using readline 5.1

Any help is greatly appreciated!

Last edited by pandora (2012-09-27 08:07:07)

Re: cannot load such file -- mysql2/mysql2

Strange: The required file was not mysql2.rb but mysql2.so. Changed die file
/usr/local/share/gems/gems/mysql2-0.3.11/lib/mysql2.rb as follows:

# require 'mysql2/mysql2'                                                                                                                     
require '/usr/local/lib64/gems/exts/mysql2-0.3.11/lib/mysql2/mysql2'

The path is for
/usr/local/lib64/gems/exts/mysql2-0.3.11/lib/mysql2/mysql2.so

and the error has gone. See
mysql2-issues

I think, this is a rather ugly solution ...