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.
Related
Is there anyway I could install MySQL gem for rails without Xcode? Many sites have mentioned XCode as optional requirement for installation. But Command line tools is installed.
I have installed rails , ruby, homebrew, MacPorts without XCode.But MySql gem could not be installed
Note: I have installed Command line tools for Xcode. But not full Xcode.
I have followed these references,
http://scotty-t.com/2012/04/02/intstalling-mysql-5-5-on-os-x-mountain-lion/
With setting path in bash_profile
But I keep on getting these errors while trying
sudo gem install mysql
Errors
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
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... 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
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.9.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.9.0/ext/mysql_api/gem_make.out
Should I install XCode first? Thanks in advance!
While you exec sudo gem install mysql, you're installing a gem which names mysql, not the database. This gem depende on a file named libmysql, which come with the mysql database.
In other words, you have to install mysql db on your machine first, then install the gem. Otherwise, the gem can't build because it can't find the file it need.
Since you have homebrew, you can install mysql db by exec brew install mysql. After that, sudo gem install mysql could work.
Do you have installed mysql-devel ? If not, try this
$ sudo yum install mysql-devel ;sorry it's for fedora
do it for lion, then
$ gem install mysql
If there still is error, try add a config path when you install the gem.
I'm stuck trying to figure out how to get OS X Lion with a XAMPP installation's MySQL to work with the mysql2 gem in rails.
Here's what I've tried:
Installed the XAMPP Dev Kit
Installed mysql5-server with both port and brew. Both of which I've now uninstalled. As it didn't fix the problem.
Installed mysql5 community edition from DMG file. Now uninstalled as it didn't fix the problem.
Downloaded 32-bit version of mysql5 community edition as a tar. Extracted folder to '/var/mysql'
Here's the command I'm running to try and get it installed:
gem install mysql2 -- --with-mysql-dir=/var/mysql --with-mysql-include=
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config=
/Applications/XAMPP/xamppfiles/bin/mysql_config
I'm at a loss how to get this to work. The only thing I can think of is that I'm somehow not pointing to the directories correctly. I've tried removing /include/, /mysql/ and /lib/ from the with-mysql-include, with-mysql-dir and with-mysql-lib configuration options. No luck with that. I've tried pointing those to the XAMPP installation. No luck still.
The error returned is:
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-mysql-dir=/var/mysql --with-mysql-include=/var/mysql/include --with-mysql-lib=/var/mysql --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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
--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/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-mysql-config
Gem files will remain installed in /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
It'd be better not to bother with the stuff XAMPP provides, and to just install a fresh copy of MySQL, and simplify your Gem command for installing mysql2:
brew install mysql
gem install mysql2
You were getting errors with installing the gem after installing MySQL through Homebrew because of all this:
--with-mysql-dir=/var/mysql --with-mysql-include= \
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config= \
/Applications/XAMPP/xamppfiles/bin/mysql_config
So removing it solves the problem.
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
I get this error:
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-config=/Applications/MAMP/Library/bin/mysql_config
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... 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.
I've tried everything here but I still get the error. For some reason when I run locate mysql_config this is the result I get:
/Applications/MAMP/Library/bin/mysql_config
/Applications/MAMP/Library/share/man/man1/mysql_config.1
I tried running sudo gem install mysql2 -- –with-mysql config=/path/you/identified/above/mysql_config twice using each path but I still get the error from above. I downloaded a fresh version of MySql and I have Xcode, but I still get these errors. What am I doing wrong?
Is the MAMP install the only install of mysql you have? If you've installed it from the mysql package then I think mysql_config will be installed in /usr/local/bin/mysql_config, so you might want to try:
sudo gem install mysql2 -- –with-mysql-config==/usr/local/bin/mysql_config
FYI, the /Applications/MAMP/Library/share/man/man1/mysql_config.1 path is clearly wrong. That's pointing to the man file for mysql_config not the actual executable.
Just to be certain, you did try this right? (exactly as written)
sudo gem install mysql2 -- –with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
Also, I'm not sure that mysql packaged with MAMP has the header files you need. You might be best to install mysql from http://dev.mysql.com/downloads/mysql/ and then try to install your gem. In this case I think it will just work.
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.