Installing Mysql 2 gem fails

試著忘記壹切 提交于 2019-11-29 13:22:55

You're installing an older version of the gem (0.4.5). I had the same issue (using 0.4.3). Installing version 0.4.10 solved this for me.

Try this:

gem install mysql2 -v 0.4.10

If that installs cleanly, you'll have to update your Gemfile to require this version:

gem 'mysql2', '~> 0.4.10'

Don't install a newer version of the gem (i.e. 0.5.x), they won't work with Rails 4 or older releases of Rails 5 (before 5.0.7/5.1.6) (see https://github.com/brianmario/mysql2/issues/950).

According to MySQL 5.7 document MYSQL_SECURE_AUTH has been enabled by default in 5.7, because of that the mysql2 not compile below the version 0.4.10 to the MySQL => 5.7

Another alternative that worked for me here was to install MariaDB, that too specifically version 10.0.x

$ brew install mariadb@10.0
$ brew link mariadb@10.0 --force

To auto-start MariaDB Server, use Homebrew's services functionality, which integrates with macOS launchctl:

brew services start mariadb@10.0

Now, the installation of mysql2 will work like a charm.

$ gem install mysql2 -v '0.4.6'
Building native extensions. This could take a while...
Successfully installed mysql2-0.4.6

I made it work by installing MySQL from dmg package https://dev.mysql.com/downloads/mysql/5.7.html#downloads

I think you can remove everything in Gemfile.lock. After try bundle install again and your Project will be running ok.

Try to unlink and reinstall mysql:

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