rails `require’: cannot load such file — mysql2/mysql2 (LoadError)

Problem

You want to use a different ruby version from the one you have initially installed and build your application with, but when you change it in your rvm installation you get the following error:

Solution

To make it work again you will have to uninstall the mysql2 gem and install it again in the new ruby version with the option –platform=ruby.

mysql2 gem error with bundle install in Rails 3.0.x

Problem
When you try to create a new Rails 3.0.x application, and try to use the ‘mysql2’ gem in your Gemfile without specifying a version you get the following warnings:

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

Solution
Specify the latest version of mysql2 that is compatible with the Rails 3.0.x versions as in:

gem 'mysql2', "~> 0.2.7"