Question

I am getting some errors whilst connecting to MySQL and the fixing of it led me to upgrade the mysql2 gem.

I ran this command to install mysql2:

ruby install mysql2

and now "gem list" shows this gem: mysql2 (0.3.2)

But I think it isn't part of my application environment still since the server gives this error:

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)

I have RVM and I've used bundler to make a gemset for this application. How can I add mysql2 to this application's gemset?

This is my gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

gem 'mysql2' , '0.3.2' 

And this is my MySQL adapter version:

$bundle show mysql2
/home/agenadinik/workspace/udfr/mysql2/ruby/1.9.1/gems/mysql2-0.3.2

Also

$ rvm gemdir /home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4: warning: Insecure world writable dir /home/agenadinik in PATH, mode 040777 /home/agenadinik/.rvm/gems/ruby-1.9.2-p180

Was it helpful?

Solution

Note that you cannot use mysql2 version 0.3.x with Rails version less than 3.1.x. I assume you are using Rails 3.0.x or below (and thus you need to use mysql2 version 0.2.x):

Here is an example of how to set up a gemset and the Gemfile to use mysql2:

~/code/myapp $ rvm gemset create myapp
~/code/myapp $ rvm use @myapp
<<<<<Edit the Gemfile and add the line gem "mysql2","0.2.7" then save and exit editor.>>>>>
~/code/myapp $ bundle install
~/code/myapp $ bundle show mysql2
<<<<<Output should be similar to: /home/<your-name>/.rvm/gems/ruby-<some-version>@myapp/gems/mysql2-0.2.7>>>>>

OTHER TIPS

If you're using Bundler, you should add

gem "mysql2"

to your Gemfile, then run bundle install

On Rails >= 3.2.0 you will see this if you are using an older version of bundler. Update bundler to >= 1.1.1:

gem update bundler

Once you have done this, update your gems:

bundle install
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top