Sunday, February 13, 2011

MySQL Gem and “uninitialized constant MysqlCompat::MysqlRes” on Linux

Stumbled across the same MySQL Gem error (uninitialized constant MysqlCompat::MysqlRes) that I ran into recently on OSX/Snow Leopard when upgrading/building the MySQL 2.8.11 Gem against MySQL 5.5 client libraries on Linux.

Steps to fix this are below:

... assuming you've already unpackaged the mysql source into a directory (my steps assume it's in /usr/local/mysql) ...


  1. Install the MySQL Ruby gem w/ the correct architecture (-arch i386 for 32bit or -arch x86_64 for 64bit): env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

  2. Check if an existing mysql library configuration file exists for the linux shared library (ld) in /etc/ld.so.conf.d directory.

  3. If the library exists, edit it and update the path to your source (/usr/local/mysql/lib)

  4. If the library DOES NOT exist, create a new file named "mysql.conf" containing "/usr/local/mysql/lib" (echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf).

  5. run "ldconfig"



You can verify your MySQL gem's library references by using "ldd" on the "mysql_api.so" file within the gem's installation directory:

BEFORE (w/out update):

ngeren@....:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib# ldd mysql_api.so
linux-gate.so.1 => (0xb7f50000)
libmysqlclient.so.16 => not found
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7f15000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7eee000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7ee5000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7ee1000)
libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7eaf000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d51000)
/lib/ld-linux.so.2 (0xb7f51000)

AFTER:

ngeren@.....:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib# ldd mysql_api.so
linux-gate.so.1 => (0xb809a000)
libmysqlclient.so.16 => /usr/local/mysql/lib/libmysqlclient.so.16 (0xb7d47000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7d2e000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7d07000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7cfe000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7cfa000)
libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7cc8000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b6a000)
/lib/ld-linux.so.2 (0xb809b000)

2 Comments:

At 4:57 AM, Anonymous Anonymous said...

After hours and hours of searching around, the before/after section made me realise I's misspelt the path in LD's config file! Thanks!

 
At 8:58 AM, Blogger /dev/noel said...

Glad to help!

 

Post a Comment

<< Home