moved a rails app of mine onto a new server and had to install a few gem dependencies. However, after installing the mysql gem I get the error, uninitialized constant Mysql
This problem appeared with me, after upgrading Ubuntu from 9.10 to 10.04.
It appears to be a problem with the mysql gem.
Symptoms: Any use of ActiveRecord that requires a connection to mysql yields a stack trace coming from "uninitialized constant MysqlCompat::MysqlRes"
I tried a "gem update mysql" and found that I couldn't build native extensions because the compiler can't find the mysql_client library. That library (libmysqlclient.so.16) sits in /usr/lib.
Fix for ubuntu 10.04:
As root, I did these:
apt-get install libmysqlclient-dev
gem install mysql
I notice that several different people are trying things here and I wonder if we're not locating the root cause.
Variables that people need to clarify in their answers:
sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
also worked for me when arch flag and symlinks didnt! THANKS!!
Setting the proper ARCHFLAGS upon gem (re-)installation helped me.. without any symlinking required:
http://joergbattermann.tumblr.com/post/181479575/fixing-the-nameerror-uninitialized-constant
I tried everything else here, but still got the problem. Downgrading from MySQL 5.5 to 5.1 fixed it for me. (Mac OS X 10.6.5)
Basically the problem is the the dynamic library libmysqlclient can't be found. The above solutions will work, but you need to reapply them any time you rebuild the gem, or when you install a new version of MySQL.
An alternative approach is to add the MySQL directory containing the library to your dynamic load path. Putting the following in my .bashrc file solved the problem:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
on my Mac OS X 10.6 I did this to install the 2.8.1 gem, which worked perfectly with my MacPorts mysql5-server:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql