sajad torkamani

This finally worked for me on macOS Monterey 12.3 (M1 Pro):

 gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1

Make sure you read the installation instructions. Notable points for me were:

  • Make sure MySQL is installed (brew install mysql)
  • Make sure XCode select tools are installed (xcode-select --install)
  • Set the with-mysql-dir option to wherever mysql was installed (check with brew info mysql)