[ACCEPTED]-Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6-gem

Accepted answer
Score: 63

It seems that it cannot find the MySQL library. Have 3 you installed MySQL?
Try installing it via 2 homebrew:

brew install mysql

or install it via macports or fink or whatever 1 you prefer.

Then try again with:

gem install mysql2
Score: 57

This command worked for me:

gem install mysql2 -- --srcdir=/usr/local/mysql/include


Score: 27

Following command worked for me successfully.

x.x.x 1 = version of mysql2 you want to install.

gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include
Score: 20

I don't need MySQL on Mac OS X, because 2 I have MySQL installed on Vagrant box. Therefore, I 1 just installed mysql-connector-c.

brew install mysql-connector-c
gem install mysql2
Score: 6

To fix for a manual gem install:

brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"

To fix for 1 all bundle installs:

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install
Score: 4

The following worked for me

brew install mysql 
brew install mysql-connector-c
gem install mysql2


Score: 4

If you used homebrew to install mysql, brew install mysql,this worked 5 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 4 you want to install
y.y.y = the version 3 of mysql you have installed ls /usr/local/Cellar/mysql to find it.

to 2 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 1 to install with bundle:

bundle config build.mysql --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
Score: 3

You'll have to specify some additional environment 4 variables to install this gem on the 64 3 bit architecture for Mac OSX 10.6:

env ARCHFLAGS="-arch x86_64" gem install mysql2

If you 2 are using rvm you can add this as your default 1 option in the ~/.rvmrc file:

rvm_archflags="-arch x86_64"
Score: 1

I had the exact same issue and errors trying 14 to install mysql2. I thought my mamp install 13 of MySQL would work fine and spent a few 12 hours playing around with paths to get that 11 to work - no success.

Finally came across 10 this post from ALoR and installed a fresh 9 version through homebrew - however - be 8 sure to follow ALL the instructions from 7 homebrew! I missed a few steps and wasted 6 another hour tracking down that problem 5 - here are those instructions: https://stackoverflow.com/a/11061487/1241271

After MySQL 4 was successfully installed, I ran: sudo gem install mysql2 and 3 it worked like a charm.

Hope this helps 2 someone from wasting several hours because 1 they neglected to read the docs (newb mistake).

Score: 1

Make sure openssl is installed on Mac via 1 Homebrew.

brew install openssl

Install mysql2 gem.

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/i
Score: 1

This is what worked for me:

gem install mysql2 -v 'x.x.x' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
  • x.x.x: replace it with the mysql2 gem version you want to install


Score: 0

I know this has been answered multiple times 8 however, here's what's working for me with: May 7 20, 2019 OSX Mojave 10.14.4 MySQL Ver 14.14 6 Distrib 5.7.24, for osx10.14 (x86_64) using 5 EditLine wrapper ruby 2.5.0p0 (2017-12-25 4 revision 61468) [x86_64-darwin17] Rails 3 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 2 whatever your current valid path is from 1 "/usr/local/Cellar/mysql"

Hope this helps!

Score: 0

I had same problem after upgrading to Catalina 9 (10.15.x)

My Gemfile.lock has defined mysql2-0.3.20, which 8 I could not get installed. But it worked, when 7 I upgraded it to mysql2-0.5.2

gem update mysql2 -- --srcdir=/usr/local/include/mysql/

Be sure that 6 you have installed mysql with brew.

brew install mysql
brew link mysql                                                                                                               

(Linking 5 /usr/local/Cellar/mysql/8.0.18... 95 symlinks 4 created)

However, after this the gem mysql2 3 was installed, but the bundle update mysql2 2 didn't work.

But this other answer helped 1 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

More Related questions