Running Rails on OS X with MySQL 5.0.24 24

Posted by Bob Silva Tue, 12 Sep 2006 18:27:00 GMT

While installing all the pre-requisites for running Rails on my new Mac Pro, I ran across a problem with either the mysql gem or mysql 5.0.24 where it depends on 'ulong' being defined by the OS include files. On OS X it isn't, and this causes the ruby mysql gem to fail compilation which causes Rails to (possibly) throw a Lost Connection to MySQL Server during query error due to the fact that the built-in Ruby driver doesn't work with mysql 4.1+ authentication (edge rails fixes this limitation with the built-in mysql driver). A quick fix for this is to edit the ruby gem mysql.c and add the #define for a ulong so the gem can properly compile.
#define ulong unsigned long


Comments

Leave a response

  1. atmos about 2 hours later:
    Hmm, I'm only on 5.0.22 but I installed the gem from darwinports without issue. port install rb-mysql5 compiled without problems. I might need to upgrade to 5.0.24 to see if they fix it for you or not.
  2. Bob Silva about 10 hours later:
    Hi atmos, Yea, the port install may be fixed but I don't use darwin ports. I found one other guy also with .24 that had the same problem, but he didn't post any other info about it. Who uses darwin ports to install gems anyways?
  3. atmos about 11 hours later:
    I was busy, it just worked so I went with it. :)
  4. Brad Madiuk 2 days later:
    Hey Bob, we worked together at Bnet a few years back. My apologies for posting this on your blog, however I know you're into RoR dev and so is Gabe Bauman. My company had paid him $8,000 as a 50% deposit on some work, and he decided to high tail run off to the mountains with it and cut off all communication including cell phone, email, home phone etc. Not to mention delete the Basecamp we had worked on. If you run into him in future, don't let a past working relationship sway you into giving him a chance. We got scammed hard. Maybe he will see one of these posts and feel guilty and finish the work or refund us, but I doubt it.
  5. Bob Silva 5 days later:
    Hi Brad, All I can say is you reap what you sow. Bob
  6. Brad Madiuk 6 days later:
    That's all well and good, and you obviously have no idea what happened aside from company propoganda. Nevertheless there's the warning. Take care.
  7. Bob Silva 6 days later:
    Thanks for the warning Brad, but after working with Gabe for over a year, I'm already aware of the dangers of hiring him. Sorry Gabe, but you really were a terrible "employee". And if Brad's story is true, then my impression of you as a "person" isn't too different.
  8. Hach 11 days later:
    Ok a bit of a newb question. I found mysql.c to edit and did so, but when I run: sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql it will overwrite the gem (presumably downloading a new copy) and thus remove the edit. what is the obvious thing I am missing? Thanks!
  9. Bob Silva 12 days later:
    just run make after you edit the file
  10. Peter Woolcock 14 days later:
    Hi Bob, Sorry to leave this here but couldn't find your contact info. I need some direct support on a Pdflib project using personalization server would you be able to help? Please let me know Peter Woolcock 416-660-4931 or pwoolcock@sympatico.ca. Are you available for contract work? Please advise Thanks
  11. Jarkko Laine 21 days later:
    Thanks, Bob, for tracking this down. Had the same problem with the same setup (MySQL OS X binary 5.0.24 + mysql gem 2.7).
  12. Spike 22 days later:
    After making the edit with a successful "make" and "make install," my ruby script still complains about mysql. Instead of being an unknown constant, now it's just "no such file to load -- mysql," as if the path isn't working. (/usr/local/mysql is there.) Any simple thing I'm missing after finishing the edit?
  13. Bob Silva 22 days later:
    Spike, Look in your site_ruby/1.8/iARCH directory for the mysql.bundle to make sure its there. If not redo the make and make install and trace from there.
  14. Michael Simons 26 days later:
    Hi Bob, i'm trying to fix my gem as well. I use sudo gem install mysql -- blah blah include dirs It fails and says: Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection. Where is that mysql.c that i can edit? I Just find a mysql.c.in in the above directory and editing that file doesn't work. Any help appreciated! Thanks from germany, Michael.
  15. Cyril 26 days later:
    Hi Michael, I used to have the same probleme as you : even mysql.c.in is re-written by the package so you can't modified it... I didn't find any way, perhaps it was obvious but anyway I modified stdlib.h in /usr/include/ and put the #define in it... it works for me. regards
  16. Michael Simons 26 days later:
    Cyril: Thanks a lot, that did the trick!
  17. Okada 3 months later:
    I am using Mysql 5.0.27 and Rails 1.2RC1 on OSX 10.4.8. "Lost connection to MySQL server during query" was happening all the time. Installing mysql 2.7 gem following this instructions solved the problem. For others trying to follow the instructions: When you try to install the gem, you see the error. Go to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 (or the equivalent on tour machine). All gem files will be there. Make the change to mysql.c and run "make", "make install" and "make clean". Thanks, Bob.
  18. Daniel 4 months later:
    Thanks for the tips and Okada thanks for the clarification. Just a note that I was getting the lost connection error when running rake db:schema:load from my OS X client with the target mysql database running on a rimuhosting server ... the different being the server was MySQL 4.1, not 5. However, the described fix worked for this setup as well.
  19. Ruben 4 months later:
    The fact that ulong is not defined on OSX is not a bug in MySQL/Ruby, but a bug in mysql itself (http://bugs.mysql.com/bug.php?id=22227)
  20. Aaron 4 months later:
    I am running into another problem I don't see listed here. My mysql.c file is located here: /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/mysql.c I edit the file, adding the #define..... First I was just running make, it was spitting out this message: gcc -fno-common -g -O2 -pipe -fno-common -I. -I/usr/local/lib/ruby/1.8/i686-darwin8.8.1 -I/usr/local/lib/ruby/1.8/i686-darwin8.8.1 -I. -DHAVE_MYSQL_H -I/usr/local/mysql/include -fno-common -c mysql.c {standard input}:unknown:FATAL:can't create output file: mysql.o make: *** [mysql.o] Error 1 Next I did a sudo make. gave me this.. gcc -fno-common -g -O2 -pipe -fno-common -I. -I/usr/local/lib/ruby/1.8/i686-darwin8.8.1 -I/usr/local/lib/ruby/1.8/i686-darwin8.8.1 -I. -DHAVE_MYSQL_H -I/usr/local/mysql/include -fno-common -c mysql.c cc -dynamic -bundle -undefined suppress -flat_namespace -L"/usr/local/lib" -o mysql.bundle mysql.o -L/usr/local/mysql/lib -lmysqlclient -lz -lm -lpthread -ldl -lobjc /usr/bin/ld: warning /usr/local/mysql/lib/libmysqlclient.a archive's cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (can't load from it) lchadrinex:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 aaronsh$ sudo make install mkdir -p /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib /usr/bin/install -c -m 0755 mysql.bundle /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib From that message it looks like maybe I have the wrong mysql? I have an intel mac. But I was sure I grabbed the mysql intel version.. Would that be what this message is from? Now when I fun irb require 'mysql' I get this:: dyld: NSLinkModule() error dyld: Symbol not found: _mysql_stmt_store_result Referenced from: ./mysql.bundle Expected in: flat namespace Any Ideas?
  21. Aaron 4 months later:
    That above sucked. Anyway here was the question.. I've gotten mysql to make and install.. but now when I run irb require 'mysql' I get this message: dyld: NSLinkModule() error dyld: Symbol not found: _mysql_stmt_store_result Referenced from: ./mysql.bundle Expected in: flat namespace any ideas?
  22. Aaron 4 months later:
    I figured out my own mistake.. I accidentally grabbed mysql ppc. not x86.. ha.. Anyway, I got it to correctly make, and install.. But now, the only way mysql correctly get's required when I do irbrequire 'mysql' is when i'm in the /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 directory.. how can I fix this issue?
  23. John bachir 5 months later:
    Thanks so much for this-- it was a real lifesaver. However I was not able to figure out which file to change and how to include that in the build until i found this article: http://jlaine.net/2006/10/3/installing-ruby-mysql-driver-on-os-x Consider linking to that in the body of this post. Thanks again!
  24. Chris 5 months later:
    Okay so I've got it all working after following the instructions from the above link. An odd behavior is that when I now do a gem list, mysql does not show up as an installed gem...however, when in irb, I can require it and proceed as normal, no complaints. Anyone else have this issue?
Comments