Errors Installing mysql2 gem via the Bundler - mysql

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.

Related

"Could not create Makefile" when trying to install mysql gem

I am running Ruby v2.3.3 on Debian 9.6. I executed this command in the terminal: sudo gem install mysql.
This gave me an error.
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.
Here's the full text of the error: https://pastebin.com/raw/HZcL2UtF
Here's the contents of mkmf.log: https://pastebin.com/raw/Bki5e9tT
Why can't I install the mysql gem? How do I fix this error?
Usually that means that you don't have required mysql libs on your system.
Try execute:
sudo apt-get update
sudo apt-get install libmysqlclient-dev libmysqlclient16
Then run mysql gem installation again:
sudo gem install mysql

Error when trying to install app with mysql2 gem

Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error:
Fetching: mysql2-0.3.18.gem (100%)
Building native extensions. This could take a while...
p
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/5.6.25/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/travis/.sm/pkg/active/lib'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86
I tried uninstalling every version of mysql I installed via homebrew and reinstalling them, like so:
brew uninstall --force mysql && brew install mysql
Then running:
sudo gem install mysql2
As suggested by a number of similar questions asked on here, but it still results in the same error as above.
Please could someone offer guidance on how to get this up and running?
For anybody still experiencing the issue:
When you install openssl via brew, you should get the following message:
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
You can set these build flags (for the local application) by running the following:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
This worked for me.
See bundler's documentation for more information.
The error log says:
ld: library not found for -lssl
So, you need to install libssl:
brew install openssl
As it was pointed out in comments, there might be a need to export the path to the library.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Try this:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
(Update version as appropriate)
The solution for me was to install the Xcode Command Line Tools.
I had recently updated Xcode through the Mac App Store, and every time I do that, I've found that I have to reinstall the Command Line Tools again.
xcode-select --install
Based on the solution here
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
solved the problem.
After Homebrew update (openssl#1.1) there is a new path for libs, so may use:
bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)
bundle install
It will fix ld: library not found for -lssl error
Thanks #mudasobwa for pointing me in the right direction. It turns out the error was caused by an unlinked openssl file, so running:
brew reinstall openssl && brew link openssl --force
Solved the problem. I found the solution here: OpenSSL, RVM, Brew, conflicting error
On MacBook air M1(macOS) it worked for me.
Install zstd
brew install zstd
Install mysql2
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
From here:
https://gorails.com/setup/osx/10.14-mojave
The combination of commands solved it me. I am on Mojave.
brew reinstall openssl && brew link openssl --force
and then
gem install mysql2 -v '0.4.10' -- \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include
Steps for me on Monterey M1 Mac
brew install openssl#3
brew install zstd
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
bundle config --local build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib"
bundle install
Seems that you miss the main files needed to build mysql2 gem
sudo apt-get install libsqlite3-dev libmysqlclient-dev -y
libsqlite3-dev is not mandatory but install it since it's the default rails DB.
Mac Catalina using Homebrew fix:
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
the following command works for my Mac os 12.1 MacOs Monterey
gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include
Please refer this link for more details
https://github.com/brianmario/mysql2/issues/1175
This finally worked for me on macOS Monterey 12.3 (M1 Pro):
gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1
Make sure you read the installation instructions. Notable points for me were:
Make sure MySQL is installed (brew install mysql)
Make sure XCode select tools are installed (xcode-select --install)
Set the with-mysql-dir option to wherever mysql was installed (check with brew info mysql)
Combining the answers given by Aleksei Matiushkin and Alexey Mozorov fixed the problem for me.
But I also updated the openssl before adding the path.
Thanks!
I've been coding with mysql2 gem for years and have encountered with this issue time to time.
Today I found that this magic option -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include no longer worked on my Mac. Indeed, it looks like the default location where brew installs openssl has changed:
$ brew reinstall openssl
...
If you need to have openssl#3 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl#3/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl#3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl#3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl#3/include"
So following the message, I had to make a few changes to the command and got it work finally:
$ gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/opt/homebrew/opt/openssl#3/lib --with-cppflags=-I/opt/homebrew/opt/openssl#3/include
Hope this will help someone!
This helped me on MacOs 12.6 (Monterey)
brew install mysql openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
gem install mysql2 -v '0.5.3' \
--source 'https://rubygems.org/' -- \
--with-cppflags=-I/usr/local/opt/openssl/include \
--with-ldflags=-L/usr/local/opt/openssl/lib
bundle install
Thanks https://github.com/brianmario/mysql2/issues/1175#issuecomment-1069721834
I found that I had to use --with-opt-dir=/usr/local/opt.
Specifically, I added the following to my ~/.bundle/config file:
BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt"

mysql.h is missing .... (Ruby on Rails, OSX)

I tried several ideas ... none of them worked ...
I'm just trying to install mysql2 as a gem. My mysql is working, but every time my system says, that mysql.h is missing ... Has someone an idea? It's very frustrating now ...
I'm using osx 10.8.3, ruby 1.9.3, rails 3.2.13 and home-brew.
gem install mysql2 -v '0.3.11'
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
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/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
--with-mysql-config
--without-mysql-config
file `which mysql`
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
What worked for me in Mountain Lion Rails install(using Homebrew and RVM) was editing /usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config
and removing -Wno-null-conversion -Wno-unused-private-field from cxflags and cxflags options as follows:
Before:
cflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
After:
cflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
After that gem install mysql2 proceeded without hickups
Note: this is probably due to a change introduced to mysql_config after 5.6.10: http://bugs.mysql.com/bug.php?id=69645
Using a package manager like Homebrew or MacPorts makes it fairly straight-forward to fix this. The binary distribution of MySQL direct from Oracle and the one bundled with OS X itself does not have the development headers, of which mysql.h is one of them.
Homebrew would fix it like this:
brew install mysql
MacPorts is very similar:
sudo port install mysql
Both of these install libraries, a command-line client and the associated development headers for the libraries. Enabling the server is optional.
As an alternative, you can get the source direct from Apple and install it whatever way you see fit.
Generally Homebrew is the best way to go.
Installing a gem sometimes involves compiling source. In this case the MySQL gem needs to create the ruby interface by compiling the C code -- you most likely need to install the MySQL development files.
(missed the OSX reference earlier)
You need to install the development headers for mysql, using brew you might need to install a lower version than 8 since some header files are removed from this distribution. For instance the my_global.h is removed, so if you code uses this header you will be forced to install a previous version then 8.
Header File Dependencies
We have started cleaning up header files dependencies, i.e. work on
“include what you use” and on reorganizing header files to remove
build dependencies. We have fixed ambiguous include paths; almost all
should now be from the root. Incrementality has increased a lot after
e.g. my_global.h went away, and sql_class.h was also reduced a fair
bit in weight. Shipped client headers are self-contained and much more
sane. For example, client headers are now platform independent (no
difference between 32- and 64-bit Linux).
brew install mysql#5.7 mysql-client#5.7
If you're using the standard XAMPP this could be the problem, you could probably need to install xampp-devel which is the development package for xampp, this distribution contains mysql headers *.h files as well as other related sources, you can find older versions in here.
you can than copy the include directory in your /Applications/XAMPP/xamppfiles then install gem using this command:
sudo gem install mysql2 -v 0.3.21 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config --with-mysql-include=/Applications/XAMPP/xamppfiles/lib/include/ --no-ri --no-rdoc
this version worked for me, and don't need to include --with-mysql-dir if you specify mysql_config path, and then you should get a similar output:
This could take a while...
Successfully installed mysql2-0.3.21
Parsing documentation for mysql2-0.3.21
Installing ri documentation for mysql2-0.3.21
Done installing documentation for mysql2 after 0 seconds
1 gem installed
you may also need to provide rails with the correct version of libmysqlclient, here is an example using Symlink:
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
Don't forget in update bundle packages.

gem install mysql2 fails

I got this error:
sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
checking for rb_thread_blocking_region()... no
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=/usr/bin/ruby1.8
--with-mysql-config
--without-mysql-config
Gem files will remain installed in /var/lib/gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /var/lib/gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
I have tried:
uninstall mysql2 and install it again
uninstall mysql with apt-get
installd dev-tools from mysql
and almost all the pages on Google
How can I fix this?
You need to install libmysqlclient-dev before installing the mysql2 gem:
sudo apt-get install libmysqlclient-dev
gem install mysql2
This should fix this problem on the latest Ubuntu versions.
Thank Andre Schweighofer, just to it
sudo apt-get install libmysqlclient-dev
gem install mysql2
..
bundle update
bundle install
DONE !!!
It require to install mysql development package
yum install mysql-devel
Its helful to use the search here ;): ruby-mysql
here is another thread ;) with the same problem: ruby-mysql2
and many more when you search for "ruby mysql2" or something like this.
These are multiple causes of this failure :
Bad versions compatibility between ruby and rubygems
Missing libmysqlclient-dev
gem not locating the
Mysql 32bit on a 64 bit system
Solutions
Install rvm with latest stable release, You can switch after via rvm between ruby versions
curl -L https://get.rvm.io | bash -s stable
Install the dependecy
sudo apt-get install libmysqlclient-dev
locate mysql_config on your system (find / -name mysql_config) and run
gem install mysql -- --with-mysql-config=/path/to/mysql_config
Install the 64 bit version of mysql for your system
It could be due to mysql updated binary ( In my case it was using Mariadb-10.0.31) and on installing the missing library( libmysqlclient-dev ), I got the following message that it would be impossible to resolve:
$ sudo apt-get install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.58-0ubuntu0.14.04.1)
But I resolved the above issue by first installing libmariadbclient-dev as:-
$ sudo apt-get install libmariadbclient-dev
It will install libmysqlclient-dev as well but by first resolving mariadb dependency.
On Ubuntu 10.10, I had to install libmysqlclient16-dev.
The way I solved was to inspect the mkmf.log, which in my case was somewhere in
./gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/mysql2-0.4.2/mkmf.log
In my case, there was an error that it could not find -lgmp, so it was missing the gmp library , so installed via apt-get , in this case libgmp-dev.

Snow Leopard + Ruby 1.9.1 + MySQL Gem = Huge problems

I tried for about 3-4 hours trying to get the mysql gem to install for ruby 1.9.1 on snow leopard. The mysql gem used to work just fine on 1.9.1 before I upgraded to snow leopard. I uninstalled MySQL server and gem from my machine. I then downloaded and installed: mysql-5.1.37-osx10.5-x86_64.dmg. I have been able to assert that this new version I installed is running as a 64bit application.
I uninstalled the mysql gem. When I tried to install the gem with this command:
env ARCHFLAGS="-arch x86_64" gem install mysql --verbose -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I got this error:
GET 304 Not Modified: http://gems.rubyforge.org/latest_specs.4.8.gz
GET 200 OK: http://gems.github.com/latest_specs.4.8.gz
Installing gem mysql-2.8.1
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/COPYING
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/COPYING.ja
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/History.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/Manifest.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/README.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/Rakefile
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/extconf.rb
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/mysql.c
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/README.html
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/README_ja.html
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/tommy.css
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/lib/mysql.rb
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/gem.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/native.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/vendor_mysql.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/test/test_mysql.rb
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/sean/.rvm/ruby-1.9.1-p243/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile
make
gcc -I. -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/i386-darwin9.8.0 -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/backward -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/mysql/include -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common -O2 -g -Wall -Wno-parentheses -fno-common -pipe -fno-common -o mysql.o -c mysql.c
In file included from /Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby.h:32,
from mysql.c:5:
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h: In function 'INT2NUM':
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h: In function 'UINT2NUM':
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:472: warning: comparison is always true due to limited range of data type
mysql.c: In function 'escape_string':
mysql.c:290: error: lvalue required as left operand of assignment
mysql.c:290: error: lvalue required as left operand of assignment
mysql.c: In function 'real_escape_string':
mysql.c:434: error: lvalue required as left operand of assignment
mysql.c:434: error: lvalue required as left operand of assignment
make: *** [mysql.o] Error 1
Gem files will remain installed in /Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1 for inspection.
Results logged to /Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I have tried everything I have read from the following links.
http://void-design.net/2009/08/05/ruby-191-mysql-and-a-snow-leopard/
http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/
Rails, MySQL and Snow Leopard
Any ideas?
Sean, I see that you are running Ruby 1.9.1 under rvm. I'm having the same problem under the same setup (Snow Leopard, rvm, MySQL 64-bit package). All of the alternate gems (mysqlplus, kwatch-mysql-ruby, etc) fail with the same error.
I would suspect the MySQL install, but everything works like a champ under the system default Ruby. So I wonder if rvm isn't the monkey wrench somehow.
EDIT: I figured it out. I installed rvm before upgrading to Snow Leopard, so my Ruby 1.9.1 install needed to be recompiled. For good measure, I reinstalled rvm from scratch.
Here's what I did:
sudo gem uninstall rvm
rm -rf ~/.gem
sudo gem install rvm
rvm-install
rvm install 1.9.1
rvm 1.9.1
env ARCHFLAGS="-arch x86_64" gem install mysql
(NOTE: You cannot use sudo when installing gems under rvm, because rvm works by modifying $PATH.)
(NOTE: I added /usr/local/mysql/bin to my $PATH so I didn't have to specify any of those awful command-line args when installing the mysql gem.)
The mysql gem installed without a hitch.
I solved this problem by installing MySQL from MacPorts and then running the same gem install command that you have up there.
So, first, uninstall the MySQL you have from the package:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
If you haven't done it yet, install MacPorts from here: http://www.macports.org/install.php
There's a package for Snow Leopard.
Install mysql5-devel from MacPorts:
sudo port install mysql5-server-devel
It'll do all the dependencies and then MySQL. Follow all the post-install steps that the installer recommends - start-up items, etc. The MySQL it installs is 64-bit.
Then install the MySQL gem with:
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5
Note the path changes there. MacPorts puts MySQL in different places.
You should be good to go.
I tried all the above steps with no luck, but discovered a workaround (or whatever) using the mysqlplus gem instead of the mysql gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysqlplus
And now my MySQL ruby apps work like a charm in Snow Leopard.
Installing XCode was the solution for me
Take a look at this post: http://jameseggers.com/post/185690322/fix-mysql-and-rails-on-snow-leopard . It shows how to get MySQL + Ruby on Rails + Snow Leopard all working perfectly.
Found a great tutorial online for this.
http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/
Setting the PATH variable was my problem.
I had the same problem with mysql gem, rvm and ruby 1.9.1. As mentioned in my post at NeptunePhoenix, I had success by installing mysql via port.
Struggled for hours before stumbling on this:
http://markgandolfo.com/2010/08/21/mysql-gem-with-rails-3-and-ruby-1-9-2
The fix with me was re-installing MySQL. I used the 64bit DMG installation version - 5.5.13
http://dev.mysql.com/downloads/mysql/