In my gemfile I have:
gem \'mysql2\'
My database.yml is as follows:
default: &default
adapter: mysql2
database: <
If you are able to upgrade your rails version, then change your Gemfile to this and it will solve the problem without downgrading the mysql2 gem version:
gem 'rails', '4.2.6'
The answer to this particular question relative to when it was posted and the version of Rails being used is that the problem is caused from doing a bundle update
and your mysql2 version updates to 0.4.x which has an incompatibility issue with latest Rails ActiveRecord.
Again, please note this is NOT the solution for people using older versions of Rails / ActiveRecord.
The quick solution is to simply specify the mysql2
version in your gemfile as follows:
gem 'mysql2', '0.3.20'
The long solution would be to wait for either an update to ActiveRecord or something in mysql2 to change.
This usually happens when you are missing some mysql packages on your machine. Do you get any errors from gem install mysql2
? What OS are you working on?
If on debian or ubuntu try sudo apt-get install libmysqlclient-dev
.
Also make sure that the gem is not placed inside a group
statement in your Gemfile.
try this:
bundle update mysql2
this command will update your 'mysql2' gem to the latest version (should be 0.3.17 or higher) and start your rails server.
Just do:
gem 'mysql2', '~> 0.3.18'
this gem works with rails version 4.x.x
if install gem 'mysql2', '~> 0.4.0'
it produces gem load error and causes compatibility issues
This issue was addressed here: https://github.com/brianmario/mysql2/issues/950
For Rails 4.x please pin the gem to mysql2 '~> 0.4.0' to avoid the 0.5.x upgrade.
Gemfile:
gem 'rails', '4.2.8'
gem 'mysql2', '~> 0.4.0'
Then run bundle update rails mysql2
I am currently using mysql v 8.0.11