ruby-on-railsrubyrubygemsmysql2

An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue - in rails project


I'm trying to create a project with mysql as a database, ran command

rails new project_name -d mysql

got the following errors

Could not find gem 'mysql2 (~> 0.5)' in locally installed gems. rails importmap:install

Could not find gem 'mysql2 (~> 0.5)' in locally installed gems. Run bundle install to install missing gems.

rails turbo:install stimulus:install Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
Run bundle install to install missing gems. "

so i ran

bundle install

but it fails and at the end it tells me

An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue

full error https://pastebin.com/jiX7V0Z0

I'm running windows (all answers I found were for linux or mac), any help is appreciated

Edit : as Christos-Angelos Vasilopoulos mentioned, answer in this issue worked https://github.com/brianmario/mysql2/issues/1210#issuecomment-965862944

what I did was the first two steps

1 - Start a cmd terminal and run ridk explicitely by running:

c:\your path to Ruby31-x64\ridk_use\ridk.cmd enable.

This gives you the right environment to do the rest.

2 - From that cmd, run

gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your path to Ruby31-x64/msys64/mingw64

(no particular quote was neeeded and I used forward slashes).


Solution

  • It is an open issue with mysql2 though there is a workaround. Check this thread from GitHub. This comment is the thing you need to resolve the problem.