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 is what worked for me. I read a ton of posts and found that using the system ruby install was causing an incompatibility issue:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
gem install -v=2.7.1 will fix it as well.
sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config also did the trick for me when migrating over to my new Snow Leopard laptop. I did not use MacPorts to install mysql, but rather the binary, and had no luck with the arch flag solutions or symlinks.
I've tried all of the above and none of them work for me either. When trying to install mysql version 2.7, I get the error:
sudo gem install -v=2.7.1 mysql -- --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
ERROR: could not find gem mysql locally or in a repository
F107PHD:stepgreen.org tdillahu$ sudo gem install -v=2.7 mysql -- --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql-5.1.39-osx10.5-powerpc/bin/mysql_config
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out
My original error:
ake aborted!
uninitialized constant MysqlCompat::MysqlRes /vendor/rails/activesupport/lib/active_support/dependencies.rb:440:in load_missing_constant'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in
const_missing'
My problem was due to my "mysql" being a 32-bit installation while ruby was 64 and 32-bit. Check with these commands
file `which mysql`
file `which ruby`
Both should match Mach-O 64-bit executable x86_64 or Mach-O 64-bit executable i386. I installed a 64-bit mysql, then
export ARCHFLAGS="-arch x86_64" ; sudo gem install --no-rdoc --no-ri mysql -v 2.7 -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config
and voila!
sudo gem install mysql -v 2.7 should do the trick...