Ubuntu14.10にMysql2をインストールする

Gemfileに MySQL2パッケージを追記

```
$ cat Gemfile
# A sample Gemfile
source "https://rubygems.org"

# gem "rails"
gem 'rspec', '~> 3.3.0'
gem 'sequel', '~> 4.25.0'
gem 'mysql2', '~> 0.3.20'
```

インストール

```
$ bundle install --path vendor/bundle
```

インストールエラー発生

```
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using diff-lcs 1.2.5
Installing mysql2 0.3.20 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/local/rbenv/versions/2.2.2/bin/ruby -r ./siteconf20150830-20802-tbrrx4.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
-----
libmysqlclient is missing. Trying again with extra runtime libraries...
-----
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 main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
-----
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', 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/local/rbenv/versions/2.2.2/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-nsllib
	--without-nsllib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-mygcclib
	--without-mygcclib

extconf failed, exit code 1

Gem files will remain installed in /home/xxx/study_ruby/vendor/bundle/ruby/2.2.0/gems/mysql2-0.3.20 for inspection.
Results logged to /home/xxx/study_ruby/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0-static/mysql2-0.3.20/gem_make.out
An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.20'` succeeds before bundling.
```

どうやら libmysqlclient-dev もしくは mysql-devel が必要らしい

```
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.
```

libmysqld-dev をインストール

```
$ sudo apt-get install libmysqld-dev
```

再度インストールで成功

```
$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using diff-lcs 1.2.5
Installing mysql2 0.3.20 with native extensions
Using rspec-support 3.3.0
Using rspec-core 3.3.2
Using rspec-expectations 3.3.1
Using rspec-mocks 3.3.2
Using rspec 3.3.0
Using sequel 4.25.0
Using bundler 1.10.6
Bundle complete! 3 Gemfile dependencies, 9 gems now installed.
Bundled gems are installed into ./vendor/bundle.
```