title: Rails 4 - Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded
body: <p>In my gemfile I have:</p>
  
  <pre><code>gem 'mysql2'
  </code></pre>
  
  <p>My database.yml is as follows:</p>
  
  <pre><code>default: &amp;default
    adapter: mysql2
    database: &lt;%= ENV['db_name'] %&gt;
    username: &lt;%= ENV['db_user'] %&gt;
    password: &lt;%= ENV['db_pass'] %&gt;
    host:     &lt;%= ENV['db_host'] %&gt;
    pool: 32
    socket:   &lt;%= ENV['socket'] %&gt;
  
  development:
    &lt;&lt;: *default
  
  production:
    &lt;&lt;: *default
  </code></pre>
  
  <p>I've run both <code>bundle update</code> and <code>bundle install</code> and my Gemfile.lock shows mysql2.</p>
  
  <p>However when I run <code>rake db:migrate</code> I get this on both my computer and on the staging server:</p>
  
  <pre><code>myproject.com(master)$ rake db:migrate
  WARNING: Use strings for Figaro configuration. 10000012508 was converted to "10000012508".
  WARNING: Use strings for Figaro configuration. 860526407370038 was converted to "860526407370038".
  rake aborted!
  Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
  .....
  </code></pre>
  
  <p>Just to make sure there wasn't a bad version of mysql2 or something, I did <code>bundle clean --force</code> and ran <code>bundle install</code> and <code>bundle update</code> again and when I run <code>gem list</code> I see <code>mysql2 (0.4.0)</code> and no other versions.</p>
  
  <p>Any ideas would be most appreciated.</p>
  
  <hr>
  
  <h2>SOLUTION</h2>
  
  <p>It's currently an issue with Rails 4.1.x and 4.2.x, per this <a href="https://github.com/rails/rails/issues/21544" rel="noreferrer">bug report</a>, it will be fixed in the next release of rails 4.2.x (credit to dcorr in comments for the link).</p>
  
  <p>In the mean time you can fix by doing downgraded to version 0.3.18 of mysql2 by adding this line to your gemfile:</p>
  
  <pre><code>gem 'mysql2', '~&gt; 0.3.18'
  </code></pre>