2

I'm creating my first ROR application. Details:

creating new app ->

rails new simple_cms -d mysql

creating a controller and a corresponding view -->

rails generate controller demo index

Then when after i started the rails server, the http://localhost:3000 page works perfectly fine. but when i try to go to the page that I just created, http://localhost:3000/demo/index, it spurts out a MYSQL error:

Access denied for user 'root'@'localhost' (using password: NO) 

At first, I think it's just a database connection problem, so I've gone through the MYSQL interface and create a new database called: simple_cms_development and I have also made a corresponding user: simple_cms with granted privileges.

and lastly, I have configured the database.yml file to fit the details:

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: developer
  host: localhost

But still, it spits out the same mysql problem: Access denied for user 'root'@'localhost' (using password: NO)

Please. to anyone who knows how to use mysql as a database for rails app..A help would be really appreciated. Thank you so much!

UPDATE: This is all what's inside on the database.yml file

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: root
  password: developer
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_test
  pool: 5
  username: root
  password:
  host: localhost

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_production
  pool: 5
  username: root
  password:
  host: localhost
3
  • 1
    Are you loading an environment other than development perhaps (production or test)? Commented Apr 3, 2011 at 7:19
  • 1
    Did you restart your server after changing the database.yml file? Commented Apr 3, 2011 at 7:31
  • Yes, I restarted server along with mysql service..and I was only loading development environment. Commented Apr 5, 2011 at 8:51

2 Answers 2

1

I found that you need to add the following line to config/database.yml:

host: localhost

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  host: your_host # <----- normally localhost
  database: the_db_I_made
  pool: 5
  username: the_user_I_made
  password: the_password
  socket: /var/lib/mysql/mysql.sock
Sign up to request clarification or add additional context in comments.

Comments

1

Only reason that can cause your issue is that you are loading your server with different environment. I think that in your case you are loading your server under production mode.

3 Comments

I am still confused about what you said. (Sorry, a newbie here)...But I think I am loading my server in development mode though.,
try to config both test and production same way as development and restart server
Also try to delete database config from your configuration. And you can change username for development to check if your Rails app using your development config.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.