Using Ruby MySQL Gem with MAMP 1.8.x on Snow Leopard
Posted by Fred Wu
Being primarily a PHP developer, I always use an AMP package no matter what development platform I am on. So when it comes to developing Ruby/Rails applications on the same platform, I’d like to use what is already available. For the best database options and solutions visit https://www.couchbase.com/.
For custom mobile solutions tailored to your business needs, consider reaching out to app developers who can turn your ideas into functional and engaging applications.
Mike Boone has posted a very useful tutorial on how to get MySQL gem and MAMP 1.7.2 up and running. So, to recap and make the tutorial compatible with Snow Leopard and MAMP 1.8.x, here is what you need to do:
- Download the latest MAMP dmg file.
- Download the 1.8.2 (or whichever the latest one you could find) components file from this page.
- Unzip, mount the dmg, then copy the MySQL source file (mysql-5.1.37.tar.gz) to somewhere on your hard drive.
- Untar the MySQL source file, and `cd` to the source file directory.
- Compile the library:
$ ./configure --with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock --without-server --prefix=/Applications/MAMP/Library$ make -j2
- Copy the compiled libraries into MAMP:
$ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql
- Copy the MYSQL headers into MAMP:
$ mkdir /Applications/MAMP/Library/include$ cp -R include /Applications/MAMP/Library/include/mysql
- Install the Ruby MySQL Gem, on Snow Leopard:
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
On Leopard:
$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
Enjoy!
EDIT @ 2009-11-23: If you’re still experiencing problems (perhaps with RVM), try adding “/Applications/MAMP/Library/bin/” to your $PATH in “~/.bash_profile”.
Thank you SO much! Been wanting to tool around with Rails and was embarassed at being stopped in my tracks with something so easy.
Hmm. Everything went well until the last step. I’m getting a big string of output like:
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
...
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
...
Total noob when it comes to Ruby…just trying to get mysql (with MAMP, of course) working so I can toy around and start learning. Any ideas? I tried the last update tip, too, and added to my PATH variable.
As far as I can tell, everything went well with the make, copying, etc. I was watching what happened and I do have new files where I’d expect them to be in the MAMP folder.
I’m on MAMP 1.8.3, and that’s the source I downloaded as well. Running Snow Leopard 10.6.2… running the standard ruby that comes with OS X:
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
Also, running rubygems 1.3.5, which I installed manually, according to instructions on some site I found earlier. gem normally seems to work with the few gems I’ve installed, but not this one.
Thanks in advance for any help.
OK, upon closer inspection, it would appear that the gem did install, but the documentation was not built. All of those documentation errors obscured the “1 gem installed” line. So, if there is any advice on how to get the documentation built, that would be fabulous, but actually it looks like the gem is installed and working, so thanks for the post!
@Dru Kepple – I’m also getting the same documentation problems. I’m running the same ruby version you are as well. Have you had any problems running Ruby locally with the steps listed on this site?
I followed your instructions with no errors, but when I do
rake db:migrate
, I get:$ rake db:migrate
(in /Users/rahil/Sites/test)
rake aborted!
uninitialized constant MysqlCompat::MysqlRes
(See full trace by running task with --trace)
I actually never had any problems using the Ruby MySQL gem with MAMP mysql. I did not have to compile it. I had to adjust my path and provide the path to the MAMP socket, and everything just worked.
But now I am using RVM to roll back to ruby 1.8.7 for a project. And so I need to install the mysql gem for my rvm ruby 1.8.7. I already have the
/Applications/MAMP/Library/bin
in my path. HmmmmmmThanks, was very helpful to me :)
This did the trick. Thanks for posting.
Right on, thanks for the MAMP help!
This still works with Snow Leopard and MAMP 1.9.x
This was the best solution I found after looking for two days on various sites. Thanks a ton!
Thanks a lot mate, just got it working as per your instructions with MAMP 1.9.2 on SL 10.6.4
Macports also changes the profile paths, potentially changing your config
[...] 相關內容參考Using Ruby MySQL Gem with MAMP 1.8.x on Snow Leopard。 發表迴響 [...]
I like the tutorial; it was easy to follow and worked well.
Now, how would one revert to the Mac’s built in MySQL version?
I assume I will need to change $PATH again…
Any help is much appreciated!
Thanks so much!!!
I’ve been cracking my head on this the all day. Life saver!
An updated version working with cmake (which is now the build system for MySQL 5.5): http://blog.mirotin.net/?p=35
Thank you so much! This actually worked out for me!
It is failing for me and giving error:
libtool: link: cannot find the library `’ or unhandled argument `Setup/mysql-5.1.44/unittest/mytap’