The blogosphere is full of a lot of posts about this particular problem, but I thought I’d chime in with my own insights. This is evidenced by two errors. First, whenever you try to do any kind of rake db task:
uninitialized constant MysqlCompat::MysqlRes
Second, you cannot install the Mysql Gem. missing libraries, or other errors, didn’t save them when I got them! Sorry.
Solution Part 1: Know Your Computer
I have an old MacBook2,1 with 64-bit core 2 duo processor. That means, it’s “x86_64” architecture. It is not “i386”. It took me a while to convince myself of this. I looked up under the Apple at the MacBook’s “about this Mac,” I read the Wiipedia site on the Mac series- FYI all kindsa nerdy details at the Model Specifications section.
Solution Part 2: Re-Install MySql & Gem
I finally got Ruby on Rails to register my MySql installed 64-bit software by doing the following:
- Check if there’s any running instances of MySQL
> ps -ef | grep mysql
- Kill them if you find them:
> sudo kill [insert pid]
- Delete the old MySql directories (if you have the Startup, go there and delete those. I didn’t.)
>sudo rm mysql*
- Uninstall Ruby’s MySql gem.
>sudo gem uninstall mysql
- I rebooted here. Not technically necessary, but it was advised somewhere, so I did it, and I think it’s a good idea.
- Download and install the MySql *for your architecture*.Mine is (x86_64)… dev.mysql.com/downloads/mysql.
- Install the gem with associated flags:
>sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/include
Note: remove the new line endings, it should all be on one line.
- Get the MySql server running –
> cd /usr/local/mysql > sudo ./bin/mysqld_safe (Enter your password, if necessary) (Press Control-Z) > bg (Press Control-D or enter "exit" to exit the shell)
- To test, go back and run that rake task.
- If you get an error about hash class detection, that’s an issue with 32-bit running on a 64-bit architecture. The 32-bit MySql and 32-bit ruby gem won’t basically work despite both being compatible with each other. This is in the library of gem data connection classes.
- If you can’t compile the gem, that’s due to it not being able to find the classes in your MySQL installation- that’s why we’re sending it all of the paths in the command line gem build.
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) (Mysql::Error)
that error is due to MySql server not running as a process on your Mac. So do that- instructions are above.
Did you like the gratuitous photo of my cat? Makes these tech posts more interesting!