I am having a problem installing the mysql2 gem.
This comes up when I do gem install mysql2
:
Marks-MacBook-Pro:~ Mark$ gem install mysql
If you used homebrew to install mysql, brew install mysql
,this worked for me:
gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
x.x.x = version of the mysql2 gem you want to install
y.y.y = the version of mysql you have installed ls /usr/local/Cellar/mysql
to find it.
to get the version of mysql
brew info mysql
mysql: stable 5.7.19 (bottled)
...
/usr/local/Cellar/mysql/5.7.19 (322 files, 233MB) *
...
then if you want to install with bundle:
bundle config build.mysql --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
I know this has been answered multiple times however, here's what's working for me with: May 20, 2019 OSX Mojave 10.14.4 MySQL Ver 14.14 Distrib 5.7.24, for osx10.14 (x86_64) using EditLine wrapper ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17] Rails 5.2.1
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql\@5.7/5.7.24/bin/mysql_config
change "/usr/local/Cellar/mysql@5.7/5.7.24/bin/mysql_config" to whatever your current valid path is from "/usr/local/Cellar/mysql"
Hope this helps!
I had same problem after upgrading to Catalina (10.15.x)
My Gemfile.lock has defined mysql2-0.3.20, which I could not get installed. But it worked, when I upgraded it to mysql2-0.5.2
gem update mysql2 -- --srcdir=/usr/local/include/mysql/
Be sure that you have installed mysql with brew.
brew install mysql
brew link mysql
(Linking /usr/local/Cellar/mysql/8.0.18... 95 symlinks created)
However, after this the gem mysql2 was installed, but the bundle update mysql2 didn't work.
But this other answer helped me https://stackoverflow.com/a/39628463/110214
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
bundle update mysql2
To fix for a manual gem install:
brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
To fix for all bundle installs:
brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install
Following command worked for me successfully.
x.x.x = version of mysql2 you want to install.
gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include
I had the exact same issue and errors trying to install mysql2. I thought my mamp install of MySQL would work fine and spent a few hours playing around with paths to get that to work - no success.
Finally came across this post from ALoR and installed a fresh version through homebrew - however - be sure to follow ALL the instructions from homebrew! I missed a few steps and wasted another hour tracking down that problem - here are those instructions: https://stackoverflow.com/a/11061487/1241271
After MySQL was successfully installed, I ran: sudo gem install mysql2
and it worked like a charm.
Hope this helps someone from wasting several hours because they neglected to read the docs (newb mistake).