views:

970

answers:

5

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

+2  A: 

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

Gordon Isnor
A: 

Switching to the ruby-mysql gem didn't work for me. Did anyone else successfully resolve this problem?

yayitswei
A: 

Hi

I think I have found the solution for the problem. In my case the problem was that the mysql gem hasn't been properly installed using the bundler . when I did this:

bundle install mysql (noobish mistake)

all gems went to mysql directory, but later on I have checked the docs of the bundler gem and did this:

bundle install bundler_files ( to know where the gems are in the future)

everything looked almost ok except that when mysql gem was installing i got some errors. I noticed that it was because of my folder path "/home/pawel/Aptana Studio Workspace/myrails_app"

If you have spaces in your folder path this gem wont install properly and later on when you modify the path to one without spaces and try to install the mysql gem IT WONT DISPLAY ANY ERRORS, but the installation will be corrupted, because you will have some extra folders there with some files etc. so

DELETE THE GEM FOLDER CREATED BY BUNDLER AND REINSTALL GEMS WITH THIS COMMAND:

bundle install

That solved the problem.

Pawel Barcik
A: 

For simple usage, which is typical (connecting, querying, iterating over results), I found mysql2 gem which is much faster than mysql or ruby-mysql gems and auto-casts values to proper types. And it installes perfectly on Snow Leopard while I couldn't get mysql gem to work.

More info at http://github.com/brianmario/mysql2

Damir Bulic
A: 

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.

Liam O'Tootle