October14
Mysql on Snow Leopard
I recently moved to using Snow Leopard on my mac pro and went thru a bit of pain getting rails and mysql to work. It turns out that ruby runs by default in 64 bit mode on snow leopard and so all my previous gems were compiled against a 32 bit ruby. So I had to re-install a list of the gems – luckily I came across this handy ruby script to show me what needed doing:
#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/Library/Ruby/Gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file path`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
gemnames = to_reinstall.map{|ginfo| ginfo.name}.uniq.delete_if{|name| name =~ /mysql|passenger/}
puts "***"
puts "Please reinstall:"
gemnames.each do |name|
gems = to_reinstall.select{|ginfo| ginfo.name == name}
puts "#{name} versions: #{gems.map{|ginfo| ginfo.version}.join(', ')}"
end
puts "or uninstall all gems that need to be reinstalled:\n"
puts "$ sudo gem uninstall #{gemnames.join(' ')}"
puts " "
puts "and reinstall them:\n"
puts "$ sudo gem install #{gemnames.join(' ')}"
But before I even got to running that script when I was trying to do a rake db:create:all I was getting this annoying error:
Couldn't create database for {"username"=>"my_username", "adapter"=>"mysql", "database"=>"my_database", "password"=>"my_password"}, charset: utf8, collation: utf8_general_ci (if you set the charset manually, make sure you have a matching collation)
So a bit more digging showed me that to avoid weird errors with mysql I should move to using the 64 bit version of mysql. So I uninstalled the 32 bit version by doing this:
sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm -rf /Library/PreferencePanes/My* edit /etc/hostconfig and remove the line MYSQLCOM=-YES- rm -rf ~/Library/PreferencePanes/My* sudo rm -rf /Library/Receipts/mysql* sudo rm -rf /Library/Receipts/MySQL*
and then installed the 64 bit version and uninstalled the mysql gem and then installed it again:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Sorry, comments are closed for this article.