0

I have the following configuration:

  • linux ubuntu 11.04
  • rails 3.0.9
  • ruby 1.9.2p290
  • mysql2 (0.2.7)

I have created first my project using "rails new" then I have modified the Gemfile to use mysql2 version 0.2.7 (I have read that later versions are working with rails 3.1 only) Then I changed the file database.yml to use mysql2 instead of sqlite3 But now I'm getting error ActiveRecord::ConnectionNotEstablished when I try to connect to a Controller. Here are the full logs:

activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:317:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.9) lib/rails/commands/server.rb:65:in `start'
railties (3.0.9) lib/rails/commands.rb:30
railties (3.0.9) lib/rails/commands.rb:27:in `tap'
railties (3.0.9) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6

PS: I tried almost all solutions provided in this website, but I still have the same issue.

8
  • I forgot to tell that the db:schema:load seems to be working :rake db:schema:load -- create_table("areas", {:force=>true}) -> 1.7675s -- create_table("properties", {:force=>true}) -> 0.0399s Commented Jul 29, 2011 at 18:41
  • What does your database.yml file look like? Which version of MySQL have you installed? Commented Jul 29, 2011 at 18:50
  • here is the dev part: development: adapter: mysql2 database: db/dev.hoha pool: 5 timeout: 5000 Commented Jul 29, 2011 at 18:57
  • Normally the database.yml for mysql2 has username, password and host fields too. Also, your database name looks weird - I'm not sure a "/" is allowed (I've never seen it like that before). Commented Jul 29, 2011 at 19:06
  • I have changed the database name and created a new mysql user with password. I confirm that the rake db:migrate and the tables are created in the mysql database. but I still have the same issue (ConnectionNotEstablished) Commented Jul 29, 2011 at 19:49

2 Answers 2

2

I ended by recreating a new project with the command

rails new -d mysql

And now the pages are retrieved without any problem! I tried to compare the automatic database.yml file and the manual one, the only diffrence I have noticed was on the user used for mysql database. in the new one the username: root is used. I came back to the old project and I changed to username/password with root ones I now it is working!!!

Sign up to request clarification or add additional context in comments.

Comments

0

I would guess that your database.yml file is incorrect. It should look something like this:

development:
  adapter: mysql2
  host: localhost 
  username: root
  password: xxxx
  database: xxxx

If that doesn't work, try changing localhost to 127.0.0.1

1 Comment

I have changed the database name and created a new mysql user with password. I confirm that the rake db:migrate and the tables are created in the mysql database. but I still have the same issue (ConnectionNotEstablished)

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.