uninitialized constant MysqlCompat::MysqlRes (using mms2r gem) - mysql

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 MysqlCompat::MysqlRes, whenever I try to run a rake command that involves the mysql database. It seems I only get this error when I require the mms2r gem. Has anyone ever heard of this? I'm running mysql 2.8.1 gem.

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

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"

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!

If you have mysql 5.5 follow this: http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/
FTR: If I didn't need some stupid rep to upvote I would have upvoted the identitcal answer, consider this my upvote.

Yes, I saw a similar error message, looking for the same nonexistent class MysqlCompat::MysqlRes
As it turns out, that class should not exist; the error message is caused by a problem with the latest Mysql driver. mysql-2.8.1 looked for my libraries in a directory named with an extra level of 'mysql' at the end. For instance, my libraries (under MacOS X 10.5.8), are in /usr/local/mysql/lib, but the mysql.bundle library looks for the MySQL libraries at /usr/local/mysql/lib/mysql ... which is wrong.
I found it easy enough to fix, by creating a symbolic link in the /usr/local/mysql/lib named 'mysql', which points to '.'
So when the libraries are referenced at that extra depth, they are found, and work. This is definitely a hack; I'm sure there are more appropriate ways to fix this. I just need it to work so I can get on with other things.
Moreover, this may not work for you. It is likely to work if your error looks like:
./mysql.bundle: dlopen(./mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib (LoadError)
Referenced from: /Users/ccullen/Projects/npapp-v2/mysql-ruby-2.8.1/mysql.bundle
Reason: image not found - ./mysql.bundle
from test.rb:5
Since this seems to be a recent development and I hadn't seen any direct response to it, I thought I'd share how I fixed it. Good luck :)

gem install -v=2.7.1 will fix it as well.

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

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:
operating system version - which version of what are you using?
where and how did you install mysql? - people here seem to have installed their mysql from source under /usr/local (I installed mine through the ubuntu packaging system)
are you on a 64bit ubuntu or 32bit? (I'm currently on 32 bit.)

With mysql gem (2.8.1) I was getting
uninitialized constant
MysqlCompat::MysqlRes
Using -v 2.7 make it work perfectly and for those who used Homebrew to install mysql
sudo gem install mysql -v 2.7 --
--with-mysql-config=/usr/local/Cellar/mysql/5.1.48/bin/mysql_config
Note that you can change mysql version if needed.

sudo gem install mysql -v 2.7
should do the trick...

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 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)

Downgrade (from 5.9) to mysql 5.1 helped on 10.6 ... running both mysql and mysql2 gems.

The mysql and mysql2 gems both work on ruby 1.9.2 just update ruby and install the gem you need.

gem uninstall mysql
gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
ldconfig /usr/local/mysql/lib/mysql
RAILS_ENV=production rake db:migrate --trace
This worked for me.

sudo apt-get install libmysqlclient15-dev

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:inconst_missing'

I had the same problem after upgrading from Fedora 10 to Fedora 12. I fixed it by just uninstalling mysql gem and installing it again. So it complies with the new version of MySQL.

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Worked perfectly for me :)

On Mac OS X 10.6.4, I had to specify the architecture and config directory:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

If your Mysql version is 5.5 you should uninstall it. I just left an article about using mysql with ruby : http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

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:
don't use default ruby install!
install ruby with macports
don't use default rubygems install!
install rb-rubygems with macports
use mysql 5.1 (not 5.5) - installed from mysql.com mac .dmg
4.
sudo env ARCHFLAGS="-arch x86_64" gem
install mysql --
--with-mysql-config=/usr/local/mysql/bin/mysql_config

sudo env ARCHFLAGS="-arch x86_64" gem install mysql
Dmg package from the mysql site an ddone!

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!!

How is the mysql dependency related to mms2r? I'm the mms2r author, btw.
The mms2r gemspec https://github.com/monde/mms2r/blob/master/mms2r.gemspec does not list a mysql dependency.

Related

Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6

I am having a problem installing the mysql2 gem.
This comes up when I do gem install mysql2:
Marks-MacBook-Pro:~ Mark$ gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
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
checking for main() in -lmygcc... 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=/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-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
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
Also when I use rails server this comes up:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
It seems that it cannot find the MySQL library. Have you installed MySQL?
Try installing it via homebrew:
brew install mysql
or install it via macports or fink or whatever you prefer.
Then try again with:
gem install mysql2
This command worked for me:
gem install mysql2 -- --srcdir=/usr/local/mysql/include
Following command worked for me successfully.
x.x.x = version of mysql2 you want to install.
gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include
I don't need MySQL on Mac OS X, because I have MySQL installed on Vagrant box. Therefore, I just installed mysql-connector-c.
brew install mysql-connector-c
gem install mysql2
To fix for a manual gem install:
brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
To fix for all bundle installs:
brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install
The following worked for me
brew install mysql
brew install mysql-connector-c
gem install mysql2
If you used homebrew to install mysql, brew install mysql,this worked for me:
gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
x.x.x = version of the mysql2 gem you want to install
y.y.y = the version of mysql you have installed ls /usr/local/Cellar/mysql to find it.
to get the version of mysql
brew info mysql
mysql: stable 5.7.19 (bottled)
...
/usr/local/Cellar/mysql/5.7.19 (322 files, 233MB) *
...
then if you want to install with bundle:
bundle config build.mysql --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
You'll have to specify some additional environment variables to install this gem on the 64 bit architecture for Mac OSX 10.6:
env ARCHFLAGS="-arch x86_64" gem install mysql2
If you are using rvm you can add this as your default option in the ~/.rvmrc file:
rvm_archflags="-arch x86_64"
I had the exact same issue and errors trying to install mysql2. I thought my mamp install of MySQL would work fine and spent a few hours playing around with paths to get that to work - no success.
Finally came across this post from ALoR and installed a fresh version through homebrew - however - be sure to follow ALL the instructions from homebrew! I missed a few steps and wasted another hour tracking down that problem - here are those instructions:
https://stackoverflow.com/a/11061487/1241271
After MySQL was successfully installed, I ran: sudo gem install mysql2 and it worked like a charm.
Hope this helps someone from wasting several hours because they neglected to read the docs (newb mistake).
Make sure openssl is installed on Mac via Homebrew.
brew install openssl
Install mysql2 gem.
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/i
This is what worked for me:
gem install mysql2 -v 'x.x.x' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
x.x.x: replace it with the mysql2 gem version you want to install
I know this has been answered multiple times however, here's what's working for me with:
May 20, 2019
OSX Mojave 10.14.4
MySQL Ver 14.14 Distrib 5.7.24, for osx10.14 (x86_64) using EditLine wrapper
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
Rails 5.2.1
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql\#5.7/5.7.24/bin/mysql_config
change "/usr/local/Cellar/mysql#5.7/5.7.24/bin/mysql_config" to whatever your current valid path is from "/usr/local/Cellar/mysql"
Hope this helps!
I had same problem after upgrading to Catalina (10.15.x)
My Gemfile.lock has defined mysql2-0.3.20, which I could not get installed.
But it worked, when I upgraded it to mysql2-0.5.2
gem update mysql2 -- --srcdir=/usr/local/include/mysql/
Be sure that you have installed mysql with brew.
brew install mysql
brew link mysql
(Linking /usr/local/Cellar/mysql/8.0.18... 95 symlinks created)
However, after this the gem mysql2 was installed, but the bundle update mysql2 didn't work.
But this other answer helped me
https://stackoverflow.com/a/39628463/110214
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
bundle update mysql2

MySQL Ruby Gem install issues

So I know that this question has been asked before, and I have looked through all of the previous answers and still can't find a solution. Hoping you all can help.
The setup: I am running Mac OS X 10.6 Server. I have used the built in MySQL install on web apps and it works great. Now I am trying to run a RoR app that requires MySQL.
So, whenever I enter
gem install mysql
it spits back the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/admin/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb --with-mysql-config=/var/mysql
*** 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=/Users/admin/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
--with-mysql-config
extconf.rb:35:in ``': Permission denied - /var/mysql --cflags (Errno::EACCES)
from extconf.rb:35:in `<main>'
Gem files will remain installed in /Users/admin/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql-2.8.1 for inspection.
Results logged to /Users/admin/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql- 2.8.1/ext/mysql_api/gem_make.out
So, through my research, I tried to specifically state the location of the MySQL install.
gem install mysql -- --with-mysql-config=/var/mysql
Unfortunately, with the same results.
Any ideas of where to go from here?
Thanks!
Kevin
Kevin,
This article may help you address your problem:
http://rapd.wordpress.com/2007/05/17/battle-against-ror-gem-install-mysql/
On Mac OSX Lion 10.7 this command helped me install the mysql2 gem:
sudo gem install mysql2 -- --with-mysql-lib=/usr/local/Cellar/mysql55/5.5.30/lib --with-mysql-include=/usr/local/Cellar/mysql55/5.5.30/include/
Before this I did install mysql55 via brew like described above.
Your milage may vary, but here's what seemed to work for us. First, ensure you have the right libraries on there first (from Apple):
http://www.opensource.apple.com/other/MySQL-53.binaries.tar.gz
Install those via:
sudo tar -xvf ~/Downloads/MySQL-53.binaries.tar -C /
Then, for our 10.6 Server, the location of mysql_config was different:
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'
Using the above worked with ruby Ruby 2.0 on Windows. I changed the library to just lib instead of lib\opt because lib\opt is not present in MySQL Server 5.5.
I picked the above command from a solution to this problem presented at:
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
I had success with this sudo gem install mysql -v '2.8.1' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
but specifying the mysql version that I need

Errors Installing mysql2 gem via the Bundler

I am trying to install the mysql2 gem via the Bundler, but it keeps dying with the following error:
** executing command
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions':
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** 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=/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
--with-mysql-config
Gem files will remain installed for inspection.
Most things I found via Googling recommended passing the --with-mysql-config parameter to fix it. So, based on:
$ which mysql_config
/usr/bin/mysql_config
I added the following to the Bundler's config:
$ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config'
However, still no luck -- same crash as above.
Since it's dying with the error mysql.h is missing, I checked for that, and it's allegedly around, just can't be found by the Bundler.
$ find / -name mysql.h
/usr/include/mysql5/mysql/mysql.h
Any thoughts?
Answer was similar to the one Wrikken posted -- here's what I did to fix it for the sake of future readers.
(This is for RHEL 5.5 -- similar but different commands apply for Ubuntu/Debian/etc.)
Doing sudo yum list installed will print out all installed packages on your machine (note: yum on RHEL requires you add a Red Hat Network repository [I use EPEL], and run it via sudo).
I had mysql and mysql-server, which explained why MySQL worked fine for every pre-existing app, but no mysql-devel, which is necessary to fix that mysql.h is missing error and similar other build errors.
Long story short, after a mysqldump -u root -ppassword --all-databases > full-dump.sql for safety, it was fixed with a simple
sudo yum install mysql-devel
For Ubuntu have to install following.
libmysqlclient-dev
libmysqlclient16
For Mac with a brew install of mysql the following solution fixed the problem for me:
I edited the mysql_config file in /usr/local/Cellar/mysql/5.6.12/bin and removed the W-compiler options -Wno-null-conversion and -Wno-unused-private-field for cflags and cxxflags.
This solved the problem with "gem install mysql2".
Reference: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html
The above problem will be occured because the mysql-devel package is not properly installed in your system. I will be explain the same in Centos of how to fix it. When you try to install that package using,
yum install mysql-devel
somtimes there will be some clash occurs with the existing packages that gets installed if you install the MySql-Administrative tool and MySQL query browser.
In that case, you need to uninstall all the existing mysql2 packages and install it again.
rpm -qa -last | grep -i mysql
yum remove MySQL-server-5.5.27-1.rhel5
yum remove MySQL-client-5.5.27-1.rhel5
yum remove mysql-gui-tools-5.0r12-1rhel4
yum remove mysql-query-browser-5.0r12-1rhel4-a
So, you can uninstall whatever mysql things displayed with rpm -qa as like above.
Then you can install the mysql-server and mysql-client.
yum install mysql-server
yum install mysql-client
Now you do the installation of mysql-devel package.
yum install mysql-devel
Now there is no package clashes and you can able to install the mysql2 gem.
gem install mysql2 -v '0.3.11'
Now your mysql2 gem will be successfully installed and you are good to go.
I got the same error. and for ubuntu 16. I had to write below command:
sudo apt-get install libmysqlclient-dev
and it work back.
In my case the problem was a misbehaving mysql_config script. When invoked by the command line with the --cflags option it would return a string of options containing:
-Xclang -target-feature -Xclang -aes -Qunused-arguments
For some reason the call to have_header('mysql.h') in the extconf.rb script would fail if those option were included.
What worked for me was to hand edit the mysql_config file removing the reference to those options from the line:
cflags="-I$pkgincludedir -Os -w -pipe -march=native -Xclang -target-feature -Xclang -aes -Qunused-arguments -O2 -g -DDBUG_OFF " #note: end space!
which I rewrote as:
cflags="-I$pkgincludedir -Os -w -pipe -march=native -O2 -g -DDBUG_OFF " #note: end space!
I know this is ancient, but if anyone still gets this zlib error, make certain that you typed:
rvm use
(whatever version you're using)
I could have sworn I did that. Just posting in case anyone is pulling their hair out and this helps. If not good luck. :)
I ran into this issue while bundle installing for redmine on fedora 23. The solution I found was to issue this command - sudo dnf install redhat-rpm-config.
Not only did this fix my issue with installing mysql2, but also for nokogiri and redcarpet.
On my Ubuntu 16.04.4 LTS running mysql Ver 15.1 Distrib 10.0.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2, the following worked:
sudo apt-get install libmariadb-client-lgpl-dev
I saw, that the error message of the current installer suggests running
apt-get install libmysqlclient-dev
This might work as well.

MySQL Install: ERROR: Failed to build gem native extension

I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql and I receive the following:
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 extconf.rb:4: warning:
Insecure world writable dir /usr/bin
in PATH, mode 040777 extconf.rb:4:
warning: Insecure world writable dir
/usr/bin in PATH, mode 040777
extconf.rb:7: warning: Insecure world
writable dir /usr/bin in PATH, mode
040777 mkmf.rb can't find header files
for ruby at
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1
for inspection. Results logged to
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.
Any ideas where I may be going wrong?
I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql and I receive the following:
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 extconf.rb:4: warning:
Insecure world writable dir /usr/bin
in PATH, mode 040777 extconf.rb:4:
warning: Insecure world writable dir
/usr/bin in PATH, mode 040777
extconf.rb:7: warning: Insecure world
writable dir /usr/bin in PATH, mode
040777 mkmf.rb can't find header files
for ruby at
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1
for inspection. Results logged to
/Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.
Any ideas where I may be going wrong?
EDIT: I installed XCode off my Snow Leopard DVD and the error just changed slightly to the following:
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
extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
extconf.rb:17: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
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
checking for main() in -lmygcc... 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
--without-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
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
doing "which mysql" on the command line returns nothing, which means it's not recognizing it. I also installed the MySQL system preferences option, and I can't stop MySQL from running. Now I'm completely stuck as what to do!
EDIT EDIT
I've just completely reinstalled MySQL using this guide http://hivelogic.com/articles/installing-mysql-on-mac-os-x
Unfortunately this didn't work either, I still receive the same errors. I can't even do mysql -uroot at the command line, I get the error of:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
So I think I've tried everything.
**SOLVED*
Sorry guys, the reason for this not working was because of the MySQL paths. I've blogged on it here: http://www.kieransenior.co.uk/2010/02/mysql-cant-connect-using-ruby-on-rails-mac-os-x-snow-leopard/
On Debian (or Ubuntu) systems, just install libmysqlclient-dev package using:
sudo apt-get install libmysqlclient-dev
and then:
gem install mysql
It will be installed without any error.
Installing the mysql gem on OSX
in a terminal.. First do a ‘locate mysql_config’ and then replace the path in the following command with where that file is.
$ sudo gem install mysql -- —–with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed mysql-2.7
1 gem installed
First of all you need to differentiate between the MySQL as Server, MySQL as Client and the Ruby bindings to MySQL.
I'm not familiar with Mac, but for *nix OS you need to install MySQL through your package manager. To get the Ruby bindings installed with
gem install mysql
you need the development headers of ruby (in Ubuntu it is the package ruby-dev) and the development headers of the MySQL-Client (currently libmysqlclient16-dev in Ubuntu). I don't know if they are named different on Mac, but after you got those installed the Ruby bindings should install without any error.
A number of people found this post helpful.
Also, I needed to do first type this:
yum install mysql-devel
and then:
gem install mysql
For some people you may need to type:
gem install mysql -- --with-mysql-config=/usr/local/mysql/mysql_config
on OSX mountain Lion: If you have brew installed, then brew install mysql and follow the instructions on creating a test database with mysql on your machine.
You don't have to go all the way through, I didn't need to
After I did that I was able to bundle install and rake.
I had a similar experience, so here are the things that I tried
Firstly, I tried to install mysql's required packages by running the command below in my terminal
sudo apt-get install build-essential libmysqlclient-dev
Secondly, I tried updating rubygems on my system by running the command below in my terminal
sudo gem update --system
But I was still experiencing the same issue.
Here’s what worked for me
After much research I realized that I was using an almost out-of-date version of the mysql gem. I simply needed to use the mysql2 gem (mysql2 gem)and not the mysql gem, so I fixed it by running the command below in my terminal
gem install mysql2
This worked fine for me. Before running the last command, ensure that you've ran the first and second commands to be sure that everything is fine on your system.
That's all.
I hope this helps
In order to resolve
Gem::Ext::BuildError: ERROR: Failed to build gem native extension
error for mysql2,
I think libmysql-ruby got changed with
ruby-mysql
Simply try with following commands,
sudo apt-get install ruby-mysql
& then
sudo apt-get install libmysqlclient-dev
I had also forgotten to actually install MySQL in the first place. Following this guide helped a lot.
http://www.djangoapp.com/blog/2011/07/24/installation-of-mysql-server-on-mac-os-x-lion/
As well as adding these lines to my .profile:
export PATH="/usr/local/mysql/bin:$PATH"
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
you can try to reinstall the latest version of xcode / dev. tools for snow leopard - this should fix your errors
if you are installing from source here is a tutorial.would be happy if it helps http://raihan90.blogspot.com/2009/03/mysql-step-by-step-hacking-into-mysql.html
Attention: You need to specify -- key, and than --with-mysql-config=/usr/local/mysql/bin/mysql_config
If you use Percona Mysql server
$ yum install Percona-Server-devel-55
$ gem install mysql
yum -y install gcc mysql-devel ruby-devel rubygems
gem install mysql2
Your Ubuntu OS need to install library for mysql client
sudo apt-get install libmysqlclient-dev
After That just install bundle or bundle install
While these answers pointed me in the right direction, on Alpine linux the package I needed was mariadb-dev, eg. run apk add mariadb-dev before the gem install mysql command.

Rails, MySQL and Snow Leopard

I upgraded to Snow Leopard using the disc we got at WWDC.
Trying to run some of my rails apps now complains about sql
(in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/
-- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
(See full trace by running task with --trace)
I could have sworn I fixed this once before. The problem is that
sudo gem install mysql
does not work and gives the error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
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
Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?
I just went through the same pain... here's what worked for me:
Download / install the 64-bit MySQL 5.1.37 from mysql.com
run the following commands:
sudo gem update --system
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)
Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).
Here's the magic command:
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.
If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
Trace/BPT trap
I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked.
sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Hope that helps someone.
I have seen this problem many times. almost everytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.
sudo gem install mysql -- --with-mysql-config=/your/mysql/config
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=/usr/bin/ruby
--with-mysql-config
Remember that you need mysql dev files to be able to build this gem.
I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.info and it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.
mesh
I thought I would answer my own question here. It seems as if the problem isnt in mysql, but in the mysql ruby bindings. I figured this out because when I hooked up Querius (my mysql gui), it was able to connect.
Here is how to build from source fix the bindings:
cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install
There are plenty of libraries that I will have to build from source on Snow Leopard and they keep popping up. MacPorts doesnt seem to be updated enough for all the libs so I'm off to do it on my own. Next up: freetype (http://download.savannah.gnu.org/releases-noredirect/freetype/)
I proceeded like explained in this post (http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/), and everything now works fine.
Remember to lookout for the typos in his command to install the mysql driver.
I had this same issue and here is what worked for me.
Install Snow Leopard and the 64bit MySQL DMG.
Create /etc/my.cnf to point to my previous MySQL data directory (as described here) and run sudo mysql_upgrade.
Opened IRB and reinstall all of my gems using (via blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html).`gem list`.each_line {|line| system 'sudo gem install #{line.split.first}'}
Uninstalled the MySQL gems I had installed.
Installed MySQL gem with sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
With that, everything seems to be working so far. *knock wood*
In case you prefer homebrew, instead of installing MySQL manually.
Un-install the existing mysql gem (if any):
sudo gem uninstall mysql
Locate the ‘mysql_config’ file:
find /usr -name 'mysql_config'
Re-install mysql gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/bin/mysql_config
Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.
Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.
I've solved it this way:
after install dmg file of mysql
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
env ARCHFLAGS="-arch x86_64"
bundle install
Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.
It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.
Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.
Install rvm:
user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
user$ source .bash_profile
Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.
user$ rvm install 1.9.2
user$ rvm use 1.9.2
Create a gemset for the rvm ruby installed in step 2 (x is the version number).
user$ rvm gemset create rails30x
user$ rvm 1.9.2#rails30x
Install Rails 3.0.x (x is the version number).
user$ gem install rails -v 3.0.x.
Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.
Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:
basedir=
datadir=
and change them to read (inserting the correct MySQL directory name):
basedir=/usr/local/mysql-version-name
datadir=/usr/local/mysql-version-name/data
Save the file. MySQL can now be started from the preferences pane.
To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the
DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your
home folder and include the following (inserting the correct MySQL directory name):
export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library
would appear and the server would abort.
Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).
user$ gem install mysql2 -v 0.2.7
Create a rails app, and it's corresponding database (appname_development).
user$ rails new appname
Add this to the app's Gemfile: gem 'mysql2', "0.2.7"
Add this to the app's database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: appname_development
pool: 5
username: username
password: pwd
host: localhost
start app and check "About your application's environment". Everything should be working correctly.
The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:
DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
to my bash profile, and this solved it for me.
I tried the archflags trick many times with slight variations but it never worked for me.
What finally did work was switching back to the version of ruby and gem installed with snow leopard.
I had built and installed my own version which has worked for me in every respect except this one.
Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.
I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql
If you are installing the mysql gem with RVM you need to use the following code to install it
sudo env ARCHFLAGS="-arch x86_64" gem install mysql
This method worked for me in Leopard Server, none of the above worked
this article solved the issue for me :)
http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html
Prior to Leopard
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
Leopard on a PPC machine:
sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Leopard on an Intel machine:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Snow Leopard (only on Intel):
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config