libmysqlclient.so.18: cannot open shared object file: No such file or directory

MySQLのアップグレード(5.5→5.7)をやっていたら、いつの間にかRedmineが動かなくなっていた。

 libmysqlclient.so.18: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2/mysql2.so (LoadError)
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2.rb:8:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2.rb:8:in `<top (required)>'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
  /var/lib/redmine/config/application.rb:7:in `<top (required)>'
  /var/lib/redmine/config/environment.rb:2:in `require'
  /var/lib/redmine/config/environment.rb:2:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
  /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:105:in `eval'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:105:in `preload_app'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:28:in `<main>'
Application root
/var/lib/redmine
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production
Ruby interpreter command
/usr/local/bin/ruby

どうやら、libmysqlclient.so.18 が無いようだ。 調べてみると、一旦mysql2のgemをアンインストールして、再度インストールすると良いらしい。 (

これだけではNGでした。)

gem uninstall mysql2
gem install mysql2 (これをやってもうまくいかないので注意)

まずmysql2の gemをアンインストールする。

# gem uninstall mysql2
Successfully uninstalled mysql2-0.3.15

次にmysql2のgemをインストールするが、エラーが発生した。「mysql-devel」が必要らしい。

#  gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
checking for ruby/thread.h... no
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/bin/mysql_config
-----
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. <strong>You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.</strong>
-----
*** 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/bin/ruby
        --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


Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.4.4 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.4.4/ext/mysql2/gem_make.out

途中のエラーメッセージにあるとおりにyum install mysql-develを実行する。


# yum install mysql-devel
# yum install mysql-devel
Loaded plugins: fastestmirror, presto, priorities
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.tsukuba.wide.ad.jp
 * extras: ftp.riken.jp
 * remi-safe: mirror.innosol.asia
 * updates: ftp.riken.jp
Package mysql-devel is obsoleted by mysql-community-devel, trying to install mysql-community-devel-5.7.13-1.el6.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.13-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================
 Package                                Arch                    Version                        Repository                              Size
============================================================================================================================================
Installing:
 mysql-community-devel                  x86_64                  5.7.13-1.el6                   mysql57-community-dmr                  3.5 M

Transaction Summary
============================================================================================================================================
Install       1 Package(s)

Total download size: 3.5 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 3.5 M
mysql-community-devel-5.7.13-1.el6.x86_64.rpm                                                                        | 3.5 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-devel-5.7.13-1.el6.x86_64                                                                                1/1
  Verifying  : mysql-community-devel-5.7.13-1.el6.x86_64                                                                                1/1

Installed:
  mysql-community-devel.x86_64 0:5.7.13-1.el6

Complete!

どうやら、公式のMySQLリポジトリからインストールしていると、mysql-develをインストールするとmysql-community-develが入るようだ。 無事に mysql-devel (mysql-community-devel)が入ったところでもう一度mysql2 gemをインストールする。


#  gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.4.4
1 gem installed
Installing ri documentation for mysql2-0.4.4...
Installing RDoc documentation for mysql2-0.4.4...

今度はうまく入った。 しかし、Redmineのページを見るエラーとなっている。 mysql2-0.3.15のGemNotFound?

Web application could not be started

It looks like Bundler could not find a gem. This is probably because your
application is being run under a different environment than it's supposed to.
Please check the following:

 * Is this app supposed to be run as the `apache` user?
 * Is this app being run on the correct Ruby interpreter? Below you will
   see which Ruby interpreter Phusion Passenger attempted to use.
 * Are you using RVM? Please check whether the correct gemset is being used.
 * If all of the above fails, try resetting your RVM gemsets:
   https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets

-------- The exception is as follows: -------
Could not find mysql2-0.3.15 in any of the sources (Bundler::GemNotFound)
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/spec_set.rb:92:in `block in materialize'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/spec_set.rb:85:in `map!'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/spec_set.rb:85:in `materialize'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/definition.rb:133:in `specs'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/definition.rb:178:in `specs_for'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/definition.rb:167:in `requested_specs'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/environment.rb:18:in `requested_specs'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:13:in `setup'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:120:in `setup'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/setup.rb:17:in `<top (required)>'
  /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
  /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
  /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/lib/phusion_passenger/loader_shared_helpers.rb:219:in `block in run_load_path_setup_code'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/lib/phusion_passenger/loader_shared_helpers.rb:333:in `running_bundler'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/lib/phusion_passenger/loader_shared_helpers.rb:217:in `run_load_path_setup_code'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:96:in `preload_app'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:28:in `<main>'
Application root
/var/lib/redmine
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production
Ruby interpreter command
/usr/local/bin/ruby

参考

Redmine超入門でLogsのプラグインを入れるとエラーがでる。 - Google グループ Redmine超入門でLogsのプラグインを入れるとエラーがでる。 - Google グループ

redmineのインストールフォルダでbundle installが必要らしい。(仕組みはよくわからない。)


# cd /var/lib/redmine
#  bundle install
Your Gemfile lists the gem spreadsheet (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem rubyzip (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Fetching additional metadata from https://rubygems.org/..
Using rake 10.2.2
Using i18n 0.6.1
Using multi_json 1.9.2
Using activesupport 3.2.13
Using builder 3.0.0
Using activemodel 3.2.13
Using erubis 2.7.0
Using journey 1.0.4
Using rack 1.4.5
Using rack-cache 1.2
Using rack-test 0.6.2
Using hike 1.2.3
Using tilt 1.4.1
Using sprockets 2.2.2
Using actionpack 3.2.13
Using mime-types 1.25.1
Using polyglot 0.3.4
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 3.2.13
Using arel 3.0.3
Using tzinfo 0.3.39
Using activerecord 3.2.13
Using activeresource 3.2.13
Using coderay 1.0.9
Using rack-ssl 1.3.4
Using json 1.8.1
Using rdoc 3.12.2
Using thor 0.19.1
Using railties 3.2.13
Using jquery-rails 2.0.3
<strong>Installing mysql2 0.3.15</strong>
Using net-ldap 0.3.1
Using ruby-openid 2.2.3
Using rack-openid 1.4.2
Using bundler 1.6.1
Using rails 3.2.13
Using rmagick 2.13.2
Using ruby-ole 1.2.11.7
Using rubyzip 1.1.2
Using spreadsheet 0.9.7
Your bundle is complete!
Gems in the groups development and test were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

しかし、今度もエラー。uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError)と出てしまう。


Web application could not be started

uninitialized constant Mysql2::Client::SECURE_CONNECTION (NameError)
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2/client.rb:12:in `<class:Client>'
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2/client.rb:2:in `<module:Mysql2>'
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2/client.rb:1:in `<top (required)>'
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2.rb:10:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/lib/mysql2.rb:10:in `<top (required)>'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
  /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
  /var/lib/redmine/config/application.rb:7:in `<top (required)>'
  /var/lib/redmine/config/environment.rb:2:in `require'
  /var/lib/redmine/config/environment.rb:2:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
  /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:105:in `eval'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:105:in `preload_app'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.21/helper-scripts/rack-preloader.rb:28:in `<main>'
Application root
/var/lib/redmine

どうやら、mysql2 0.3.17 が必要らしい。
こちらの参考サイトによると/var/lib/redmine/Gemfile を書き換える必要があるらしい。

NameError: uninitialized constant Mysql2::Client::SECURE_CONNECTIONが出た時の対処 - Qiita NameError: uninitialized constant Mysql2::Client::SECURE_CONNECTIONが出た時の対処 - Qiita

  • /var/lib/redmine/Gemfile
・
・
・
# Include database gems for the adapters found in the database
# configuration file
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
  database_config = YAML::load(ERB.new(IO.read(database_file)).result)
  adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
  if adapters.any?
    adapters.each do |adapter|
      case adapter
      when 'mysql2'
<strong>#        gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
        gem "mysql2", "~> 0.3.17", :platforms => [:mri, :mingw]
</strong>
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when 'mysql'
        gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when /postgresql/
        gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
        gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
      when /sqlite3/
        gem "sqlite3", :platforms => [:mri, :mingw]
        gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
      when /sqlserver/
        gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw]
        gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
      else
        warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
      end
    end
  else
    warn("No adapter found in config/database.yml, please configure it first")
  end
else
  warn("Please configure your config/database.yml first")
end

そして、もう一度bundle installする。

# bundle install
・
・
・

今度はうまく動作した。 ちなみに、 gem install mysql2 -v ‘0.3.17’ をやっても、ダメだった。 bundle とGemfileのバージョン管理の仕組みによるものなのだろう…