Installing the native MySQL gem (simply called
mysql) isn’t as easy as it may seem — unless you’ve installed both MySQL and Ruby using MacPorts, in which case it is.
There are a few problems that crop up when installing the
mysql gem: the build process may not find the MySQL libraries, they may build them for the wrong architecture and you may not have gotten all the required files when you installed MySQL.
To solve the first problem you need to find the
mysql_config tool, and to find that you need to find your MySQL install dir. Run
which mysql to find out where the
mysql command resides. If it starts with
/opt/local then you have probably installed MySQL with MacPorts (but since you have problems you are likely using a version of Ruby installed elsewhere, most probably the version bundled with the OS). In this case
mysql_config is at
which mysql prints out a path starting with
/usr/local you may have installed MySQL using the
.pkg installer from MySQL. This one is tricky, and you probably don’t have all the files you need. You will probably have to reinstall MySQL using either MacPorts, Homebrew or compiling it from source. Try the rest of these instructions, but if they fail reinstall MySQL using one of the methods above.
You can now find the exact location of
mysql_config by running
find /opt/local/lib -name mysql_config or
find /usr/local/lib -name mysql_config to find the exact path.
Now try to install the gem with this command:
ARCHFLAGS="-arch x86_64" gem install mysql -- \ --with-mysql-config=/path/to/mysql_config
/path/to/mysql_config with the path returned by the
find command above. If you normally install gems with
sudo to the command string.
There are some more tips on how to build MySQL from source and how to build the gem here: http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/