If you’re doing local Rails development and are attempting to setup a database using MySQL (specifically, MySQL2) and you keep getting:
rake aborted! uninitialized constant Mysql2
Here’s what I did to fix the problem:
From within the directory of your application, issue:
$ gem uninstall mysql2 $ gem install mysql2
This will make sure that you’re running the most recent version of the gem.
Next, update your Gemfile. Comment out the default SQLite reference and add a line for MySQL:
#gem 'sqlite3-ruby', :require => 'sqlite3' gem 'mysql2'
Finally, rake your database:
$ rake db:create
And that should take care of it.
Unfortunately, YMMV as this is a common problem that can be rooted in a variety of reasons.