15

Everything worked fine prior to the update. Using ruby 1.9.3p392 with RVM with rails (3.2.12) Using MySQL 5.7.16 and Nginx and Unicorn

Log shows

LoadError: libmysqlclient.so.18: cannot open shared object file: No such file or directory - /home/bill/apps/xxx/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.16/lib/mysql2/mysql2.so

I tried:

  1. uninstall/install mysql2 gem
  2. Running bundle install

Nothing worked. Anyone had that problem after updating ?

Besi
  • 22,579
  • 24
  • 131
  • 223
Henri
  • 983
  • 3
  • 11
  • 29
  • shouldn't `mysql` gem be installed and looked in directory for 1.9.3 version? (`/home/bill/apps/xxx/shared/bundle/ruby/1.9.3/..`) – andrykonchin Jan 08 '17 at 23:22
  • Yes thanks. There was a compatibility issue between my older mysql2 gem and the newly installed mysql 5.7. Changing gem version in my gemfile gives me another error – Henri Jan 08 '17 at 23:37
  • ok my error is now: LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.). mysql2 is part of the gemfile and I also installed activerecord-mysql2-adapter. I will check if it's not a socket problem – Henri Jan 09 '17 at 01:40
  • It's strange. Are you sure `Gemfile.lock` contains required gem `activerecord-mysql2-adapter` and you have run `bundle` to install this gem? – andrykonchin Jan 09 '17 at 19:37
  • Ok.. now it works. I changed my gemfile to a older version ( gem 'mysql2', '~> 0.3.17') which is compatible with my rails and mysql 5.7. Then Bundle install from my computer... pushed it to my server and cap deployed it. The error went away. Many thanks – Henri Jan 10 '17 at 05:15

1 Answers1

32

Remove and reinstall mysql2 gem.

I had the same thing. Upgraded from Ubuntu 14 to 16 and saw this same error.

To fix it, I just uninstalled the mysql2 gem and reinstalled it using bundler.

  1. Uninstall mysql2 gem:

    $ bundle exec gem uninstall mysql2
    
  2. Reinstall mysql2 gem:

    $ bundle install
    

The reason is because it has to install native extensions when it installs the gem, and a large system change like upgrading the OS 1 or more versions requires rebuilding those native extensions.

Hope that helps.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
  • 3
    Thanks. I found a fix somewhere else that suggested `gem uninstall mysql2` which did not work. Forcing it to remove it from the bundle with the `bundle exec` was the important part for me. – mr rogers Oct 08 '17 at 20:03
  • @mrrogers Yes, that's gotten me a few times. `bundle exec` is like its own environment. Also confusing is when when people do `gem install` and `sudo gem install`. Can lead to mass chaos. – Joshua Pinter Oct 08 '17 at 20:24