gem mysql2をインストール時にエラー「You’ve installed the binary version of mysql2.」が発生した場合

gem mysql2をインストール時にエラー「You’ve installed the binary version of mysql2.」が発生した場合

gemでmysql2をインストール時にエラー「You’ve installed the binary version of mysql2.」が発生した場合の対処法を記述してます。

環境

  • OS windows10 pro 64bit
  • ruby 2.7.1
  • rails 6.0.3.2

※windows10にrubyをインストールして実行する手順はこちら
※windows10にRuby on Railsをインストールして利用する手順はこちら

エラー全文

「Gemfile」に「gem ‘mysql2’」を追加して「bundle install」実行時に発生。

  You've installed the binary version of mysql2.
  It was built using MySQL Connector/C version 6.1.11.
  It's recommended to use the exact same version to avoid potential issues.

  At the time of building this gem, the necessary DLL files were retrieved from:
  http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.11-win32.zip

  This gem *includes* vendor/libmysql.dll with redistribution notice in vendor/README.

対処法

エラーメッセージに記述してあるとおりに「http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.11-win32.zip」をダウンロードして「Ruby」の「bin」ファルダ配下に「libmysql.dll」を配置する

解凍した「mysql-connector-c-6.1.11-win32」フォルダの「lib」にある「libmysql.dll」をコピー

Rubyがある「bin」フォルダに「libmysql.dll」を貼り付けます。

※自分の環境の場合は「C:\Ruby27-x64\bin」となります。

再度、実行すればエラーは解消されました。