I am trying to get a rails project up and running on my local machine. When I do bundle install
Fetching mysql2 0.3.20
Installing mysql2 0.3.20 with native ext
My MacBook Pro had a disk crash during upgrade to MacOS Mojave (not pretty!), so I had to reestablish all my code projects afterwards.
One particular project proved extremely hard to get up and running and I've spent several hours today looking for a way to get mysql2-0.3.21 running for an older RoR project; Ruby version 2.1.1p76 with Rails 4.1.1.
Finally, I succeeded by following this advice: https://github.com/brianmario/mysql2/issues/1010#issuecomment-460257986
I did the following steps:
Start by removing all installed versions of mysql2 from your gemset:
gem uninstall mysql2
Then install MySQL 5.6, I already have MySQL 8.0.17 installed, so 5.6 is installed as a keg only which is fine:
brew install mysql@5.6
Then install mysql2 version 0.3.21 with the following command:
gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
The OpenSSL part can probably be left out and you can change the mysql2 version number depending on what version of Rails your project is running.
After the above steps I was able to start the Rails console again and query the database:
Loading development environment (Rails 4.1.1)
2.1.1 :001 > User.count
(18.7ms) SELECT COUNT(*) FROM `users` WHERE `users`.`deleted_at` IS NULL
=> 1222
2.1.1 :002 >