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

I purchased a Macbook pro this week and have been trying to move my stuff from my old Ubuntu machine which completely died on me. Now those who work on linux machines know that setting up your development environment hardly takes any time and after you’ve done it about 50 times its more about going through the commands on your console.

I am not sure if this is the general opinion but I find the key bindings very inconsistent and frankly a pain to keep track of.

Anways getting back to the issue at hand I hit a roadblock while installing Mysql. I chose the 32 bit package installer for OSX and everything seemed smooth and I was able to start the server and connect, but rake db:create through this error, which drove me nuts for almost a day.

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

The error speaks very little about what the actual problem is.

Now if your using OS X 10.6 and your current architecture is the 32 bit you are still advised to install the 64 bit OS X installation, to avoid “weird issues”.

To get rid of this issue

  • uninstall your mysql gem
  • stop your mysql server
  • install the 64 bit mysql server
  • start you mysql server
  • reinstall the gem with the 64 bit architecture configurations
  • sudo env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config

This is should pretty much help you get around it.

More help here  http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard and there is a lot of information about this on the rails forum too so check this out too http://railsforum.com/viewtopic.php?id=20371

Hope this helps OSX newbies like me.