I need help with installing mysql2, how i resolve my error?

Hello I am trying to run gem install mysql2 in widowns, for a rails 7.0. Project, i am facing this error.

ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

i did try everything, but nothing works.

mysql2 is killing me , i can not get that gem to load.

Do you use WSL? Make sure that you have installed the MySQL server and the client library see mysql - Error installing mysql2: Failed to build gem native extension - Stack Overflow

1 Like

If you use MySql (Or MariaDB / etc) then would you be open to trying out the very reliable Trilogy driver? This is a fault-tolerant and highly performant alternative to the mysql2 driver, created by the loving folks at Github. An ActiveRecord adapter for it will ship with Rails 7.1, and as well it’s now available for use in Rails 7.0 via a recently-released update to the trilogy adapter gem. To use this in any Rails 7.0 project which targets MySql, put this in your Gemfile:

gem 'trilogy'
gem 'activerecord-trilogy-adapter'

And in your database.yml, change “mysql2” to “trilogy”, do a bundle, and *bam* it should work!

1 Like

Make sure you have the Ruby Devkit installed on your system. The Devkit is necessary for compiling native extensions. You can download it from the RubyInstaller website: https://rubyinstaller.org/add-ons/devkit/