Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Problems with MySQL Gem and Rake on Snow Leopard

Sep 22

I recently got a new MacBook Pro and had problems creating a new database for my Rails app on Snow Leopard. Running rake db:create left me with the following useless error:

Couldn’t create database for {“username”=>”root”, “adapter”=>”mysql”, “database”=>”delete_me”, “password”=>nil, “socket”=>”/tmp/mysql.sock”}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

Although I could manually access MySQL via command line and create the necessary databases, rake continually failed. It turns out that the MySQL gem needed to be compiled for a 64-bit OS as mentioned in this post:

http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard

The key command to run is:

sudo env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config

Then you should be able to run your rake tasks and ultimately get Rails talking to your MySQL database.

4 comments

  1. Foggerty /

    Thank you! this was driving me nuts :-)

  2. ayesha /

    Thank you man, I have wasted 5 hours on this

  3. admin /

    No problem. You gotta love those obscure errors that leave you completely in the dark!

  4. Re-install mysql-server and mysql-client using this command:

    sudo apt-get install mysql-server mysql-client

    and then some libraries you need to install to make MySQL available to ruby:

    sudo apt-get install libmysql-ruby

    This all solved my problem. Try it !!! :)

Trackbacks/Pingbacks

  1. Keksrolle.de » Blog Archive » Resolving trouble with Ruby On Rails with MySql on XAMPP on OSX Snow Leopard - [...] to http://www.techskater.com/ruby-on-rails/problems-with-mysql-gem-and-rake-on-snow-leopard/ this seems to be related to Snow Leopard and MySql 32bit vs. 64bit. On Snow Leopard the ...

Leave a Reply