Thursday, July 08, 2010

uninitialized constant Mysql while running rake db:create

1. Uninstall the mysql gem

bparanj$ sudo gem uninstall mysql

Successfully uninstalled mysql-2.8.1

2. Installing the gem the right way on Snow Leopard
bparanj$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed

3. Edit the gemfile and include the line:

gem 'mysql'

4. Run bundle install from the rails project directory:

mbp2:blog bparanj$ bundle install
Fetching source index from http://rubygems.org/
Using rake (0.8.7) from system gems
Using abstract (1.0.0) from system gems
Using activesupport (3.0.0.beta4) from system gems
Using builder (2.1.2) from system gems
Using i18n (0.4.1) from system gems
Using activemodel (3.0.0.beta4) from system gems
Using erubis (2.6.6) from bundler gems
Using rack (1.1.0) from bundler gems
Using rack-mount (0.6.6) from system gems
Using rack-test (0.5.4) from system gems
Using tzinfo (0.3.22) from system gems
Using actionpack (3.0.0.beta4) from system gems
Using mime-types (1.16) from system gems
Using polyglot (0.3.1) from system gems
Using treetop (1.4.8) from system gems
Using mail (2.2.5) from system gems
Using actionmailer (3.0.0.beta4) from system gems
Using arel (0.4.0) from system gems
Using activerecord (3.0.0.beta4) from system gems
Using activeresource (3.0.0.beta4) from system gems
Using bundler (0.9.26) from system gems
Using mysql (2.8.1) from system gems
Using thor (0.13.7) from bundler gems
Using railties (3.0.0.beta4) from system gems
Using rails (3.0.0.beta4) from system gems
Using sqlite3-ruby (1.3.0) from bundler gems
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

5. rake db:create will now work
mbp2:blog bparanj$ rake db:create
(in /Users/bparanj/projects/blog)
db/test.sqlite3 already exists