Musician, Ruby on Rails Entusiast, Composer, Programmer and Lover of Hot Sauce

Installing MySQL Gem after Installing MySQL From MacPorts

Posted: May 25th, 2010 | Author: mindtonic | Filed under: Gems, MySQL | Tags: , , | No Comments »

MacPorts is a fantastic resource for installing and managing libraries on OSX. When working with Ruby on Rails, I installed MySQL (and Postgresql) using MacPorts, but had trouble getting the MySQL gem to install and connect. The error message I received was:

Error: uninitialized constant MysqlCompat::MysqlRes

Here is the magic formula:

sudo gem install -v 2.7 --no-rdoc --no-ri mysql --
--with-mysql-dir=/opt/local/lib/mysql5
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config;

Source: http://www.ruby-forum.com/topic/192550


Convert MySql Datetime to Javascript Date Object

Posted: August 13th, 2009 | Author: mindtonic | Filed under: PHP | Tags: , | No Comments »
  function mysqlTimeStampToDate(timestamp) {
    //function parses mysql datetime string and returns javascript Date object
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
  }

Source: http://snippets.dzone.com/posts/show/4132


Ultrasphinx MySql Location Error

Posted: June 24th, 2009 | Author: mindtonic | Filed under: Rails Plugins | Tags: , , , , | 1 Comment »

After installing all of the necessary elements for Spinx and Ultrasphinx, I began following the instructions from Snax Fauna to get the system up and running.

rake ultrasphinx:configure

worked fine, but I encountered the following error upon attempting to index my models:

rake ultrasphinx:index
...
dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Referenced from: /usr/local/bin/indexer
Reason: image not found

In my configuration for development, I use the MAMP MySql server. The rake configure command correctly pulled all of the connection information from database.yml, so that was not the problem.

I searched around and finally encountered this solution from Michael Hartl:

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

It worked brilliantly. Thanks Michael.