“Active Record::Connection Not Established” Error in Ruby on Rails (ROR) when Connecting to MYSQL Server – Solution

"ActiveRecord::ConnectionNotEstablished" Error in Ruby on Rails (ROR) when Connecting to MYSQL Server

“Active Record::Connection Not Established” Error in Ruby on Rails (ROR) when Connecting to MYSQL Server – Solution

      I got this error “ActiveRecord::ConnectionNotEstablished” while using Ruby on Rails with MYSQL initially. The error means that the Rails framework is not able to connect to MYSQL server. The problem is that the root(MYSQL) user was not able to connect to MYSQL through Rails. So to solve this issue, login as root in MSQL and create a new MYSQL user and config Rails to use the new MYSQL user and password.

Create User MYSQL Command:

CREATE USER ‘user’@’localhost’ IDENTIFIED BY ‘password’;

Grant Access to Required Database to the New User:

GRANT ALL PRIVILEGES ON *.* TO ‘user’@’localhost’;

Note: The first * represents the database and second * represents the table name. *.* means that user is given access to all databases and its table. You can also give restricted access to a specific database by replacing *.* by database_name.* 

      Now use the new MYSQL user in config/database.yml file which solves the issue.

Setup Used:

  • Gem v1.8
  • Ruby v1.9
  • Rails v4.0.3
  • MYSQL Server v5.5
  • mysql2 gem in Rails
  • Rails default web server (WEBrick)

[ YOU MAY ALSO LIKE ]

Leave a Reply