I'm Jason, a web applications developer in the Denver, Colorado area.

Error: 'unintitialized constant MySQL' with Rails 3 on Snow Leopard Mac

I just installed Rails 3 on my iMac, which is running Snow Leopard. I’m trying to build a web hosting website/billing system/management system. I configured the app to use MySQL in /config/database.yml like so:

  adapter: mysql
  encoding: utf8
  database: hosting_development
  username: root

I had to do this because I created the Rails app without specifying that I didn’t want sqlite3. I then ran rake db:create and I got this error:

rake aborted!
uninitialized constant Mysql

I found an article online which advised to do the follow, with the exception of the path to mysql_config. I’m using MacPorts for most of the packages in my development environment.

$ sudo gem uninstall mysql
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql --

I then modified the Gemfile in my app with the following. I think this might have been what was needed most, not the gem reinstallation. I forgot to do this until right before it was fixed.

# gem 'sqlite3'
gem 'mysql'
comments powered by Disqus