Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Mysql Problems

Trying to start a new Rails 3 beta 4 app with mysql.... Running OS X Snow Leopard. WIth previous versions of Rails I have no problem with MySQL. But now when I start the Rails 3 app I get the following error when I click "About Your Application Environment" on the Rails index.html startup screen:

undefined method `init' for Mysql:Class

like image 697
Gordon Isnor Avatar asked Jun 28 '10 01:06

Gordon Isnor


3 Answers

Change your Gemfile to use 'mysql2', it's a more modern driver and has nicer features as other people have mentioned.

New Rails applications use the mysql2 gem by default.

like image 66
NZKoz Avatar answered Oct 22 '22 02:10

NZKoz


I ran into the same issue (RoR 3, OSX 10.6, mysql 2.8.1 gem).

You can use irb to rule out RoR:

irb
require 'rubygems'
require 'mysql'
db = Mysql.connect('hostname', 'username', 'password', 'database')

If the above doesn't work, you may want to try removing the mysql gem and reinstalling it. I came across a post saying bundle install might mess up the install without displaying errors.

sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Verify things work via irb, then start up rails again.

like image 22
Liam O'Tootle Avatar answered Oct 22 '22 02:10

Liam O'Tootle


I ended up switching from the mysql gem to the ruby-mysql gem, worked.

like image 3
Gordon Isnor Avatar answered Oct 22 '22 01:10

Gordon Isnor