Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:16:48
ALoR

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

brew install mysql

or install it via macports or fink or whatever you prefer and then try again with:

gem install mysql2
Sushma Satish

This command worked for me:

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

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 don't need MySQL on Mac OS X, because I have MySQL installed on Vagrant box. Therefore, I just installed mysql-connector-c.

brew install mysql-connector-c
gem install mysql2

The following worked for me

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

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

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

env ARCHFLAGS="-arch x86_64" gem install mysql2

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

rvm_archflags="-arch x86_64"
yellowaj

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).

BMA88

Make sure openssl is installed on Mac via 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

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!