Installing mysql2
gem errors on Apple silicon M1, M2 or M3 Mac running macOS Sonoma.
Make sure mysql-client
, openssl
and zstd
are installed on Mac via Homebrew.
Replace
mysql-client
with whichever mysql package you are using
brew install mysql-client openssl zstd
Install mysql2
gem.
Replace
0.5.2
with whichever version you are using
gem install mysql2 -v '0.5.2' -- --with-mysql-lib=$(brew --prefix mysql-client)/lib --with-mysql-dir=$(brew --prefix mysql-client) --with-mysql-config=$(brew --prefix mysql-client)/bin/mysql_config --with-mysql-include=$(brew --prefix mysql-client)/include --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix zlib)/lib" --with-cppflags="-I$(brew --prefix openssl)/include -I$(brew --prefix zlib)/include"
Solved my issue. First i had the same error like mentioned at the top of this issue, and then «Error symbol not found in flat namespace '_mysql_affected_rows'». My Mistake was that i transferred my user, including all the rvm staff from my intel mac to my M2.
So i reset my mac, installed everything new from ground up, including MacOs, brew, rvm mysql, AND: ruby. The last was the most critical for my feeling.
After that i didn't need any additional configs, like mentioned at the top of this isse, just ran
gem install mysql2
, or justbundle
without any specific configs and it all runs fine.My Ruby Projects are from version 2.7.5 until 3.1.2, mysql2 is -v 0.5.5 and a mariadb 10.11.2