Solve error when installing mysql2 with ruby 3.1

Tzung-Chien Hsieh
2 min readApr 15, 2022

This article introduces how to solve the error when installing mysql2 gem with ruby 3.1 and rails 7.0.

Before you start, please check whether you already installed the MySQL connector.

Error while installing mysql2 with ruby 3.1

I am not sure what the root cause is. I encountered an issue while switching from ruby 2.6.8 to ruby 3.1.0. When I did bundle install, I got the following error message.

I have tried the following commands, and they both don’t work. However, the second one is very close to the final answer.

gem install mysql2

or

gem install mysql2 --platform=ruby -- --with-mysql-dir="C:\Program Files\MySQL\Connector C++ 8.0"

The second command got a different error message which is can’t find library “C:\Program Files\MYSQL\Connector C++ 8.0/lib”

Solution — Copy lib64 to lib

The error message is that we can’t find the lib folder. However, we only have lib64 folder in Connector C++ 8.0. Therefore, I copy lib64 to the lib folder.

Then we run the command again, we can finally install mysql2.

--

--

Tzung-Chien Hsieh

Computer science PhD student, I will share what I learned in Programming, Machine Learning, and Rare Disorders.