Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error When Changing to MySQL2 on Heroku

For my Heroku app (Rails 3.1.4 and Ruby 1.9.2), I'm trying to change to a database that is using MySQL2, but I'm receiving an error from Heroku (which is crashing my app):

3.1.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the mysql12 adapter: `gem install activerecord-mysql12-adapter` (no such file to load -- active_record/connection_adapters/mysql12_adapter) (RuntimeError) EXCEPT

In my gemfile, I have:

group :production do
  gem "mysql2", "~> 0.3.11"
end

group :development, :test do
  gem 'mysql', '2.8.1'
end

In my database.yml, I have:

development:
  adapter: mysql

production:
  adapter: mysql2

Here's what I've tried unsuccessfully(all attempts installed correctly locally and in Heroku):

  1. Per this answer, I tried (in my gemfile), mysql2 version "< 0.3"

  2. Per another answer for that question, I tried '< 0.3.7' which didn't work

  3. I tried gem "mysql2", "~> 0.3.11" per this answer, but it didn't work

  4. Per the gem's site, I tried (in my gemfile), mysql2 version "~> 0.2.7" and it installed mysql2 0.2.18 (successfully locally and in Heroku)

like image 488
yellowreign Avatar asked May 04 '12 00:05

yellowreign


People also ask

How to use ClearDB on Heroku?

In heroku website, go to My Apps and select the app on which you have installed ClearDB. On the top corner click on Addons and then select ClearDB MySQL Database. Once there, click on your database and choose the 'Endpoint Information' tab. There you see your username/password.

Can I use MySQL on Heroku?

Heroku does not offer a native MySQL add-on but instead supplies it through a third party, ClearDB. If it has not been added to your application already, you can install it from the Heroku Add-Ons Page. Once installed, it will appear in your Add-Ons list in your Resources tab as ClearDB MySQL .

How to delete ClearDB Heroku?

Removing a ClearDB dedicated MySQL instance$ heroku addons:destroy cleardb --name=MyClearDBMaster Removing cleardb:standard-100 from myapp... done.

What is ClearDB MySQL?

ClearDB is a cloud, hybrid, and on-premise database-as-a-service for MySQL powered applications. It stores and manages your MySQL database for you so that you don't have to deal with things like database servers, replication, advanced storage, IT support, and especially things like database failures.


1 Answers

I'm sure you've figured this out or moved on long ago, but I was running into the same issue and thought I'd share what worked for me for anyone else who comes along.

In addition to what you mention above, if you're using Heroku you also have to specify mysql2:// in the DATABASE_URL instead of mysql://. See the ClearDB writeup here: https://devcenter.heroku.com/articles/cleardb

And update their instructions to use mysql2:// instead of mysql:// like so:

heroku config:add DATABASE_URL='mysql2://adffdadf2341:[email protected]/heroku_db?reconnect=true'

Hope that helps.

like image 72
Tanya Breshears Avatar answered Sep 22 '22 17:09

Tanya Breshears