RoR + XAMPP + MySQL -- Gem Install MySQL Issue - mysql

I am PHP developer by trade and I work with XAMPP. I have decided to dive into Ruby now and I want to use the MySQL installation from XAMPP for Ruby and I am having a problem getting the Gem for mysql to install properly.
The command I am executing is this:
sudo gem install mysql -- —–with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
and the error I get is this:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150126-99463-2b5bwp.rb extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
clang: warning: argument unused during compilation: '-L/Applications/XAMPP/xamppfiles/lib'
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling mysql.c
clang: warning: argument unused during compilation: '-L/Applications/XAMPP/xamppfiles/lib'
linking shared-object mysql/mysql_api.bundle
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql_api.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/mysql-2.9.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/mysql-2.9.1/gem_make.out
An error occurred while installing mysql (2.9.1), and Bundler cannot continue.
Make sure that `gem install mysql -v '2.9.1'` succeeds before bundling.
If I do a locate mysql_config, I get this:
/Applications/XAMPP/xamppfiles/bin/mysql_config
/Applications/XAMPP/xamppfiles/bin/mysql_config_editor
/Applications/XAMPP/xamppfiles/man/man1/mysql_config.1
/Applications/XAMPP/xamppfiles/man/man1/mysql_config_editor.1
I have gone through all of the help requests on SO and I cannot find a solution to my particular problem.
Any help would be appreciated. Please let me know if you need any further information.
Thanks!

This worked for me on MacOS X High Sierra using RubyGems:
gem install mysql2 -- \
--with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config \
--with-mysql-dir=/Applications/XAMPP/xamppfiles/mysql/ \
--with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ \
--with-mysql-include=/Applications/XAMPP/xamppfiles/include/ \
--no-ri --no-rdoc

I figured out with this:
bundle config build.mysql --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
gem install mysql2
my client:
require 'mysql2'
client = Mysql2::Client.new(:host => "127.0.0.1", :username => "root")

I notice the OP had XAMMP installed. Here is what I had to do to get this to work after installing XAMPP. I warn you that this is not elegant, but it does allow you to avoid a second installation of mysql
# first, fake the location of the headers
sudo ln -s /Applications/XAMPP/xamppfiles /usr/local/mysql
# second, let the libraries etc show up where they are expected:
cd /usr/local/mysql/lib/mysql
for i in ../libmysql*; do sudo ln -s $i .; done
# and finally, one last hack for dynamic loading to work
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I warned you that it was a bit ugly :-)

Related

Fail to install mysql2 on bundle install ruby

fail install mysql when run bundle install
i try to install rails project that use mysql2 as database, but i got this error when try to install mysql
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.26/lib
-----
creating Makefile
current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/usr/local/opt/openssl/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/<username>/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3 for
inspection.
Results logged to
/Users/<username>/.rvm/gems/ruby-2.6.5/extensions/-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before
bundling.
In Gemfile:
mysql2
seems like 'bundle' try to access ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
meanwhil openssl path is on : opt/homebrew/opt/openssl#1.1/lib/
how to change '-L/usr/local/opt/openssl/lib/' to opt/homebrew/opt/openssl#1.1/lib/
someone can help ?
Please install the following Linux packages if you're using Linux:
sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
many RubyGems required native libraries from them.
and run bundle install again.
The same thing happens to me in Rails 6.1.4.1 (Ruby 3.0.1p64).
I have tried to executed brew info openssl, then follow display some guide.
echo 'export PATH="/usr/local/opt/openssl#1.1/bin:$PATH"' >> /Users/user/.bash_profile
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.4

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"

Rails 3.2.3 MySQL 5.5.1 Mysql2 gem install fails with ld incompatibilities

I have a clean build system as follows
Ubuntu 11.04
Rvm 1.13.5
Ruby 1.9.3p194
Rails 3.2.3
Gem 1.8.24
MySql 5.5.24-1 (installed in /usr/local)
I am trying to install the mysql2 gem (0.3.11) and getting the following problem:
pal#smurf01:~$ sudo gem install mysql2
[sudo] password for pal:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling client.c
client.c: In function 'rb_raise_mysql2_error':
client.c:98:3: warning: ISO C90 forbids mixed declarations and code
client.c: In function 'rb_mysql_client_socket':
client.c:590:3: warning: ISO C90 forbids mixed declarations and code
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.so
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.so when searching for -lmysqlclient_r
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.a when searching for -lmysqlclient_r
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
pal#smurf01:~$
First question: Has anyone got Rails mysql2 running with MySql 5.5.1 on Ubuntu? I have it running on another system with 5.1. The gem description is vague on supported MySql versions.
Second question: Has anyone encountered this problem? I± have battled various library issues with the mysql2 gem over the passed year or so but this seems to be different.
Any assistance is gratefully recieved.
BTW: Reverting back to MySql 5.1 is a valid solution!
Regards
Peter
Or just apt-get install libmysqlclient-dev and then gem install mysql2
So the problem appears to have been a missing library and some links. Doing the following solved the issue.
Get the new and install the libmysqlclient-dev deb package kindly provided by Nathan Rennie Waldock
wget http://ppa.launchpad.net/nathan-renniewaldock/ppa/ubuntu/pool/main/m/mysql-5.5/libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb./;l
dpkg -i libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb
Then create some links that mysql2 needs as it can't seem to follow the mysql path
cd /usr/lib/
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.a .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18 .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18.0.0 .
Now happily install the mysql2 gem
sudo gem install mysql2
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysq2l-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
Had the same issue in Ubuntu 12.04 also using the ppa mentioned in the accepted answer.
But also there was no libmysqlclient file on my system with _r in the name.
Googling around I found out that package builders have started to drop the _r suffix from the files, so that might have happened between 11.10 and 12.04.
Also the paths were a bit different to the once mentioned so these are the symlinks that I had to create:
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.a ./libmysqlclient_r.a
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so ./libmysqlclient_r.so
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./libmysqlclient_r.so.18
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0 ./libmysqlclient_r.so.18.0.0
I had this problem as well...
I did dpkg -r mysql-devel as when I was trying to do apt-get install libmysqlclient-dev I got an error saying:
Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb) ... dpkg:
error processing
/var/cache/apt/archives/libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb
(--unpack): trying to overwrite '/usr/bin/mysql_config', which is
also in package mysql-devel 5.5.28-2
After doing this, gem install mysql2 worked! yay :)

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.

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/