Re: MySQL gem problem on OS X [SOLVED]



Hey, I want to say thanks for pointing me in the right direction!
Rather than completely start with new files, I new the stuff was there, it just needed a little massaging.
Here is the account I kept of what I did to fix the problem. It's not the most graceful thing, but it's not bad:

Part 1: Configuration You Never Knew You Had To Do

mysql gem manual setup for OS X 10.4.9 (probably any 10.4.x)

I've got Ruby 1.8.4 installed in /usr/local/bin
(I fixed the bad factory install long ago)

My mysql gem 2.7 is installed in the following directory:
/usr/local/lib/ruby/gems/1.8/gems/mysql-2.7

My MySQL is installed in:
/usr/local/mysql/

(actually in:
/usr/local
I have a symlink to the full name of the install to simplify the path name. I got this idea from the way other software is often installed. (such as the Entropy PHP distro))

You should navigate (in Terminal, using UNIX command cd) your way to each of those directories in separate terminal windows. This should keep you ready to check stuff. To open them as finder windows (much easier to browse) just use OS X's open command.
open /path/name/here
So, on my machine
open /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7

The terminal window open to the mysql gem's directory is where you will type all of these commands.

extconf.rb has following options:

--with-mysql-include=dir
MySQL header file directory. Default is /usr/local/include.
Mine would be
/usr/local/mysql/include
So,
--with-mysql-include=/usr/local/mysql/include


--with-mysql-lib=dir
MySQL library directory. Default is /usr/local/lib.
Mine would be
/usr/local/mysql/lib
so,
--with-mysql-lib=/usr/local/mysql/lib


--with-mysql-dir=dir
Same as --with-mysql-include=dir/include, --with-mysql-lib=dir/lib.
Mine would be
/usr/local/mysql
So, in theory, I could simply use only :
--with-mysql-dir=/usr/local/mysql


--with-mysql-config[=/path/to/mysql_config]
Get compile-parameter from mysql_config command.
Mine would be
/usr/local/mysql/bin/mysql_config
So,
--with-mysql-config=/usr/local/mysql/bin/mysql_config

Well then, let's try this all together now, shall we? It's long...
at the command line:
ruby extconf.rb --with-mysql-include=/usr/local/mysql/include --with- mysql-lib=/usr/local/mysql/lib --with-mysql-dir=/usr/local/mysql -- with-mysql-config=/usr/local/mysql/bin/mysql_config

Oops. Error message:
checking for mysql_ssl_set()... /usr/local/lib/ruby/1.8/mkmf.rb: 174:in `initialize': Permission denied - mkmf.log (Errno::EACCES)
from /usr/local/lib/ruby/1.8/mkmf.rb:174:in `open'
from /usr/local/lib/ruby/1.8/mkmf.rb:201:in `postpone'
from /usr/local/lib/ruby/1.8/mkmf.rb:541:in `checking_for'
from /usr/local/lib/ruby/1.8/mkmf.rb:600:in `have_func'
from extconf.rb:20

What the hell does that mean?! Well, error messages in Ruby can be a bit cryptic, but mainly because they're so verbose. This just said you don't have the matching permissions with those of the file you're trying access.
So what to do?
Easy! Run the same command again, but start with sudo. (often installing or configuring things at the command line in OS X requires you to do sudo, remember that when simple commands that should work fail.)
sudo ruby extconf.rb --with-mysql-include=/usr/local/mysql/include -- with-mysql-lib=/usr/local/mysql/lib --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

Password:
(enter your password for your user account)

checking for mysql_ssl_set()... yes
checking for mysql.h... yes
creating Makefile

Done.
Now part 2: The Test.
The documentation says:
ruby ./test.rb [hostname [user [passwd [dbname [port [socket [flag]]]]]]]
Ugly. That's just too many brackets. Too many optional arguments that are usually not optional to get anything done.
hmm... no file mysql.o
let's skip the test and see what happens.

Part 3: Make
Now we run the make file and cross our dirty little fingers.
make
No. No dice.
sudo make
nope, same error. Luckily, I found this earlier and it made sense: http://jlaine.net/2006/10/3/installing-ruby-mysql-driver-on-os-x
What they said was that you need to add the line
#define ulong unsigned long long
in the mysql.c file in the mysql gem's directory. If you are unfamiliar with C, just open the file in TextMate and scroll down to the first instance of #define (you will see it near the top of the file). Insert the line after the second #define statement and you should be fine. While you're there though, just to be safe and secure, add a comment line telling when you added it and why.
Ok, save and close the mysql.c file. Now run make again.
sudo make
Waiting... make often takes time and don't you dare expect to understand half the gobbledy-gook it spits out. Make also tends to have lengthy periods where there is no feedback on progress and all you can do is wait and wonder. This one is a quickie though.
Ok, that was painless (I hope) now make install:
sudo make install
And that should have been super fast.
Now go play with Ruby and MySQL as you should.

CAVEAT EMPTOR: We didn't successfully run the test.rb file. That's too bad. It was designed apparently for compiling the gem from source the old-fashioned way. Or perhaps the unit test is out of date, who knows. But it would be nice to know if everything passes! But sometimes we must live dangerously and as we say in Texas:
If it ain't broke, don't fix it.

.



Relevant Pages

  • Re: user permission problems
    ... Do you have it for SCO Openserver 5.0.6? ... set them up in the tcb and copied the kill command to their home dir. ... Install sudo. ... You will need to install oss646c first. ...
    (comp.unix.sco.misc)
  • Re: New Debian31r1 Install - help me optimize - TNT2 - sudo - KDE - Xwindows
    ... I have no 'sudo', no sudoers file, no man pages, no 'hdparm' commands ... lucky with the big 'apt-get install kde' command). ... But aptitude does have the ability to search. ...
    (comp.os.linux.misc)
  • Re: very basic about initial install
    ... Whats up with total avoidance of a simple command line? ... I switched to Ubuntu to see if it would install and boot... ... usually some way provided to access it as root without running around ... Apparently `sudo' is that way with Ubuntu, ...
    (Ubuntu)
  • Re: root (was: Need help moving from 10.4 to 10.5)
    ... I was just trying to do a make install on a ... could have done an "sudo ksh" along the lines suggested by Jolly Roger ... It's a better practice than logging in as root, ... This way, each command is logged, which means there is traceability. ...
    (comp.sys.mac.misc)
  • Re: Setting Env
    ... The command should be ... the default install of freebsd, ... I had some permissions problems earlier with this installation and ended up chowning everything to mysql. ... Download and play hundreds of games for free on Yahoo! ...
    (freebsd-questions)