I need to put together a rails app today. Its been about a year since the last time I started a new project and I am on a new laptop running snow leopard now.
After updating my gem source and installing the newest version of rails, I created my new rails project. I choose mysql as my db type and set about creating a couple migrations. When I tried to run my migrations I found that I had not installed the mysql gem. I installed the mysql gem but all was not well. Well it was less not well than it appeared but here was the output of the install command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | $ sudo gem install mysql Password: Building native extensions. This could take a while... Successfully installed mysql-2.8.1 1 gem installed Installing ri documentation for mysql-2.8.1... No definition for next_result No definition for field_name No definition for field_table No definition for field_def No definition for field_type No definition for field_length No definition for field_max_length No definition for field_flags No definition for field_decimals No definition for time_inspect No definition for time_to_s No definition for time_get_year No definition for time_get_month No definition for time_get_day No definition for time_get_hour No definition for time_get_minute No definition for time_get_second No definition for time_get_neg No definition for time_get_second_part No definition for time_set_year No definition for time_set_month No definition for time_set_day No definition for time_set_hour No definition for time_set_minute No definition for time_set_second No definition for time_set_neg No definition for time_set_second_part No definition for time_equal No definition for error_errno No definition for error_sqlstate Installing RDoc documentation for mysql-2.8.1... No definition for next_result No definition for field_name No definition for field_table No definition for field_def No definition for field_type No definition for field_length No definition for field_max_length No definition for field_flags No definition for field_decimals No definition for time_inspect No definition for time_to_s No definition for time_get_year No definition for time_get_month No definition for time_get_day No definition for time_get_hour No definition for time_get_minute No definition for time_get_second No definition for time_get_neg No definition for time_get_second_part No definition for time_set_year No definition for time_set_month No definition for time_set_day No definition for time_set_hour No definition for time_set_minute No definition for time_set_second No definition for time_set_neg No definition for time_set_second_part No definition for time_equal No definition for error_errno No definition for error_sqlstate |
Which seems very ominous but if you notice at the top it does actually say the gem was installed. The errors have to do with the RI and RDoc installations.
However I found that even though the gem installed correctly I could still not run my migrations. After digging around a bit and spending a couple hours trying out different suggestions from the net I finally found my magic bullet. It appears when you install mysql 5.1 on snow leopard and want to use the mysql gem you need to install specify the config location and the arch type.
So without further ado, the magic command to get mysql 5.1 working with Rails 2.3.4 on Mac OS X Snow Leopard was…
1 | sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config |
HTH,
sim
14 Responses to “Gem Mysql with Mysql 5.1 on Snow Leopard”
Trackbacks/Pingbacks
- Tea-Driven Development :: Installing mysql gem on Mac OSX Snow Leopard - [...] This old chore doesn’t seem to have become any easier lately. Here’s how to do it: http://blog.simb.net/2009/10/24/gem-mysql-with-mysql-5-1-on-snow-leopard/ [...]

Thanks much. The command at the bottom is exactly what I needed to build the MySQL gem.
Glad it helped Rob. I know I wasted way more time than I would have liked to on it. :)
That got me past that error, bug now my app just says:
rake aborted!
Constant MysqlCompat::MysqlRes from mysql_compat/mysql_res.rb not found
Constant MysqlRes from mysql_res.rb not found
Any ideas?
i owe you a beer, my 3 hour saga with mysql has ended.
Wow. Great job on the fix :)
+1
gem install mysql –no-ri –no-rdoc
and you are done
Thank you so much! I went to over 20 sites, and yours was the first to provide a working solution. Thank you again!
Wow, thank you very much!
Wow Simeon, thank you!!! Exactly what I needed. I probably shouldn’t have been so blindly following some of the tutorials to get this all running in the first place, but your leg work saved me.
cut –> paste –> enter –> boom!
All set!
THANK YOU!!
Incidentally, where do you do your digging around, to find solutions/suggestions on these kinds of errors? I’d googled for hours before I found your magic bullet.
Hey Josh,
Glad I was able to help. There is no silver bullet. I have been running linux systems for a really long time. So there are tips and tricks you pick up about how Unix and C code works.
Good Luck.
sim
it might be obvious but I replaced the hardcoded path to the mysql_config with `which mysql_config` as I installed mysql itself through homebrew…thx for the hint!
Excellent – the `–with-mysql-config=/path/to/mysql_config` tweak works sweetly on Gentoo x86_64 using an rvm environment with MySQL 5.1.51. Thanks so much for posting this in a google-friendly post!
Problem: rake db:migrate gives ‘Object is not missing constant Issue!’
App: Redmine
FIXED
:-D
– Thomas
I had the same issue on Fedora 14, and this solved it neatly. Thanks!