There's not much more to my question than that. gem install mysql doesn't work and I haven't found anything by Googling.
When I try gem install mysql2, this is what I get. I don't know what to do now.
jason#buster:~/projects/mcif-rails$ gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/jason/.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... yes
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=/home/jason/.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 /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
It looks like you still need to install MySQL's development libraries. These are required for the gem to build successfully on your system.
[Edit] Seems the RoR Wiki is no longer available. But, Ubuntu has offered their own walkthrough which suggests:
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo gem install mysql
See http://wiki.rubyonrails.org/database-support/mysql#installation for more detail.
Example: Ubuntu
sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
libmysqlclient15-dev mysql-client-5.0 mysql-common
sudo apt-get install libmysql++-dev
sudo gem install mysql
I'll just leave this here:
I ran into a similar problem, then realized I couldn't install the mysql2 gem without having MySQL installed on my development machine (even though I'm only using the mysql2 gem to connect to a remote MySQL server).
::forehead slap::
brew install mysql
then, in my Gemfile:
gem 'mysql2', '~> 0.3.11'
followed by a quick
bundle install
Success!
If you are running Rails 3 you should use the mysql2 gem. You can install it with:
gem install mysql2
You will need to first install MySQL and any development headers. This will vary across different operating systems. On Ubuntu, you can run:
aptitude install mysql-server
aptitude install mysql-client
aptitude install mysql-common
aptitude install libmysql-ruby
aptitude install libmysqlclient-dev
If you are creating a new project, use:
rails new sample --database=mysql
cd sample
bundle install
For more details, check out the project repository.
I assume you are working with Rails.
In your Gemfile:
gem 'mysql2'
Then in your terminal:
bundle
In 2013, Using Ubuntu 12.04, this worked for me:
sudo apt-get install mysql-client libmysqlclient-dev
bundle install
Related
I am trying to use the mysql 2 gem with Rails, so I added gem 'mysql2'. I am not able to install it using bundle install, and it gives me this error.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/Ben/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150307-17143-1jx7cob.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()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... 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
--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/Ben/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
--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-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
extconf failed, exit code 1
Gem files will remain installed in /Users/Ben/.rvm/gems/ruby-2.2.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/Ben/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-14/2.2.0/mysql2-0.3.18/gem_make.out
An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.
I have no idea how to get it to work, so any help would be appreciated.
Here is some info on my computer.
ruby -v => ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
gem 'rails', '4.1.5' (rails -v won't work)
bundler -v => Bundler version 1.8.4
OS: Mac Yosemite
For Mac Users:
brew install mysql
gem install mysql2
For Ubuntu Users:
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
sudo gem install mysql2
Installing the libmysqlclient-dev gives you the necessary files to compile the mysql2 gem which is what Rails will use to connect to MySQL when you setup your Rails app.
Finally, run bundle install
try to install 'libmysqlclient-dev' first
sudo apt-get install libmysqlclient-dev
and after run
bundle install
Make sure that you install your gems using bundler.
Run
bundle install
or simply
gem install mysql2
Then include it in your database.yml file
I figured out my problem, I was running rails server in RubyMine, but for some reason, RM was using an old version of ruby. Changing the project's sdks worked perfectly!
Not an OS specific answer, but may help others:
Newer MySQL2 adapters (v0.4.x) are not compatible with Rails 4.1.5.
Specifying an older mysql2 gem (eg v0.3.x) fixes the issue:
gem 'mysql2', '~> 0.3.21'
Source: https://github.com/brianmario/mysql2/issues/675
When I attempt to run the following in Terminal, I receive an error that prevents the installation of mysql gem:
I run:
sudo gem install mysql
I receive the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/(myuseraccount)/.rbenv/versions/2.1.5/bin/ruby extconf.rb
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/(myuseraccount)/.rbenv/versions/2.1.5/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
extconf failed, exit code 1
Gem files will remain installed in /Users/(myuseraccount)/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/mysql-2.9.1 for inspection.
Results logged to /Users/(myuseraccount)/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql-2.9.1/gem_make.out
Please tell me if you know how I can fix this error and install the mysql gem
Install mysql2 gem rather than mysql and be sure to have MySql installed before install the gem:
brew install mysql
gem install mysql2
bundle install
Error was:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
..................
An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue.
Make sure that gem install mysql2 -v '0.4.10' succeeds before bundling.
...................
Solution was:
gem update --system
sudo apt-get install libmysqlclient-dev
And then "bundle install" was OK.
I'm trying to use vagrant on my MAC OSX machine. I connected vagrant with using SSH and I set ruby 1.9.2-p290. Now I'm try to install ruby gems but I've been facing with this problem when I want to install mysql2 gem.
Fetching: mysql-2.8.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/home/vagrant/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
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... yes
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=/home/vagrant/.rbenv/versions/1.9.2-p290/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 /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/mysql-2.8.1 for inspection.
Results logged to /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I set in Gem file
gem 'mysql2'
and again I run bundle command but the result is the same.
Why doesn't mysql run on vagrant?
The mysql2 gem has native C extensions that build against mysql binaries.
Your vagrant machine needs to have mysql installed.
Do something like this
$ vagrant ssh
$ sudo apt-get install mysql-server mysql-client
After mysql is installed, you should be able to install the mysql2 gem.
EDIT: you also need the mysql development libraries so
$ sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev
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 am trying to install the mysql 2.8.1 gem. I would be using it to build a Rails 2.0.2 application on Ubuntu 10.04. I would be using Ruby 1.8.7. I have installed the development dependencies(other gems). For some reasons I am unable to install it. I am not able to exactly figure out how to fix it. Please help!!
I get the following in the terminal when I try to install it:
mohnish#pc146724-desktop:~/Downloads$ sudo gem install mysql-2.8.1.gem
Building native extensions. This could take a while...
ERROR: Error installing mysql-2.8.1.gem:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
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... yes
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=/usr/bin/ruby1.8
--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 /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
mohnish#pc146724-desktop:~/Downloads$
Thanks for your help!!
Try this and then install the mysql gem:
sudo apt-get install libmysqlclient-dev
If that's not sufficient try it like this
sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev
Try this and then install the mysql gem:
sudo apt-get install libmysqlclient-dev libmysqlclient16
This worked after then running sudo gem install mysql.
The documentation still doesn't install correctly (heaps of "No definition" errors, although thats not really a biggie.
You should do what the error message tells you: check the mkmf.log! Search for this file using find /usr/lib/ruby/gems/1.8/gems/ -name mkmf.log. Usually, this error message appears because you forgot to install the -dev package for the extension you were trying to install. So if you wanted to install the mysql gem, you probably forgot to install the libmysqlclient14-dev first. Do an apt-cache search | grep dev to find the appropriate packages.
plz check this for more information
In my case, I had the following error message:
An error occurred while installing mysql (2.8.1), and Bundler cannot
continue. Make sure that gem install mysql -v '2.8.1' succeeds
before bundling.
I tried: gem install mysql -v '2.8.1', and I got an error message similar to what you got.
I fixed it doing the following:
STEP (1): run this: sudo apt-get install libmysqlclient-dev
STEP (2): install mysql: gem install mysql -v 2.8.1
You should get a success message similar to this:
Successfully installed mysql-2.8.1 Installing ri documentation for
mysql-2.8.1 1 gem installed
I hope my answer helps.