Problems with MySQL Gem and Rake on Snow Leopard



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.



2 Responses to “Problems with MySQL Gem and Rake on Snow Leopard”

  1. Foggerty says:

    Thank you! this was driving me nuts :-)

Leave a Reply