1

My installation

  • Ubuntu 10.10
  • Rails 3
  • gem = sqlite3 and sqlite3-ruby
  • gem = mysql2

Now I created a application called mytestapp, using

rails new mytestapp

As usual with rails 3 it defaults to using sqlite3 database. Now I wanted to change the database for mytestapp so that it uses MySql database.

I made changes here

  • database.yml
  • gemfile - I added gem 'mysql2' and removed gem 'sqlite3'

My new database.yml looked something like this

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: mytestapp_development
  pool: 5
  username: mytestapp
  password: hacked
  socket: /var/run/mysqld/mysqld.sock

Now I goto localhost:3000 and click on the about application's development environment I get the following error

ActiveRecord::ConnectionNotEstablished

MySql user mytestapp has proper permissions for the database.

Infact when I create a new rails app using the following

rails new anotherapp -d mysql

It works great. What can be missing here.

1 Answer 1

2

Have you ran bundle install after editing your Gemfile?

If you did, then try to run the following command to see what's the difference between your hand-edited application and the new you created with -d mysql:

diff /path/to/hand-edited-app /path/to/rails-created-mysql-app
Sign up to request clarification or add additional context in comments.

2 Comments

ok the diff command showed me that gemfile.lock also had sqlite as its dependency. So should I change it by hand or use some command. Maybe bundle install. I have no idea.
You change Gemfile.lock by running bundle install.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.