gem install mysql2 fails - mysql

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.

Related

mysql2 gem install fails with unmet dependencies: libmysqlclient-dev

I am experiencing a similar issue to this poster on the askubuntu forums. I've started with a clean Ubuntu 14.04 install several times now and keep getting the same error no matter what I do.
The following packages have unmet dependencies:
libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.46-0ubuntu0.14.04.2) but 10.0.23+maria-1~trusty is to be installed
E: Unable to correct problems, you have held broken packages.
Reproducing the error:
Followed the instructions on the MariaDB site for version 10.0. I tried 10.1 as well in a previous attempt.
I have Ruby (2.2.3) on Rails (4.2.5) installed on my server. Setup my app, configure the Gemfile and bundle install
An error occurred while installing mysql2 (0.4.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.2'` succeeds before bundling.
Then I gem install mysql2 -v '0.4.2' and get the following:
mysql client is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.
So I apt-get install libmysqlclient-dev and get the error Unable to correct problems, you have held broken packages as seen in the first part of this post.
Infos:
apt-cache policy libmysqlclient18 &
libmysqlclient18:
Installed: 10.0.23+maria-1~trusty
Candidate: 10.0.23+maria-1~trusty
Version table:
*** 10.0.23+maria-1~trusty 0
500 http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu/ trusty/main amd64 Packages
100 /var/lib/dpkg/status
5.5.46-0ubuntu0.14.04.2 0
500 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
5.5.35+dfsg-1ubuntu1 0
500 http://mirrors.digitalocean.com/ubuntu/ trusty/main amd64 Packages
What step am I missing that will get the bundle install to not encounter issues with the mysql2 gem (and still use MariaDB)? mysql -uroot -p works okay from the terminal.
purge all mysql related packages
sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get update
Now, that you have a clean system. Try installing mariadb again
sudo apt-get install mariadb-server libmariadbclient-dev mariadb-client mysql-common libmysqlclient18 libmariadbd-dev
just ensure that package version you are being promted to install are the same as given on this page:
http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.0/ubuntu/pool/main/m/mariadb-10.0/
Otherwise, it will install Mysql packages from Ubuntu's official repo which will cause the conflict.If that happens, you should set maria db repo with higher priority as given on this page:
https://askubuntu.com/questions/293619/assign-higher-priority-to-ppa
Hope it helps

Installing MySQL with rails without Xcode

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.

OS X Lion with xampp + rails + mysql2 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.

MySQL Ruby Gem install issues

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

Errors Installing mysql2 gem via the Bundler

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