gal
gal

Reputation: 302

Problem when I run my server on localhost (ruby on rails)

When I type rails server in my CMD the server works and I can go to localhost:3000. But after i get this messege in the CMD and the same message in the browser on localhost:3000 in the errors section.

Started GET "/rails/info/properties" for 127.0.0.1 at 2010-12-02 21:14:55 +0200

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

Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (30.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (97.0ms)

What is the issue?

here this is 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: mysql2 encoding: utf8 reconnect: false database: simple_cms_development pool: 5 username: root password: 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:passwordex
  host: localhost

Upvotes: 1

Views: 3735

Answers (2)

David Elner
David Elner

Reputation: 5201

I know you already found the solution to your problem, but I'm going to post this as an answer anyways, for those who might stumble across this same issue.

Having the same exact Access denied for user 'user'@'localhost' (using password: NO) problem, it turns out my database.yml file was malformatted. The reason? YAML doesn't allow certain characters: I happened to be using a '!' in my password, and for whatever reason, the YAML parser reading this database.yml file ignored my password line like it wasn't there, hence the (using password: NO), even though I explicitly declared it.

Solution? Changed my password not to include any YAML special characters. I suppose there might be a way to escape it, though. Annoying nonetheless.

Upvotes: 3

Keith Gaddis
Keith Gaddis

Reputation: 4113

You're using root for your mysql user, but not supplying the root password in config/database.yml.

Incidentally, while its usually ok in development, using the root mysql user in production or for staging is a Very Bad Idea™.

here's a typical mysql config section:

production:
  adapter: mysql
  database: app_production
  username: root
  password: password
  pool: 5
  timeout: 5000
  encoding: utf8

Upvotes: 1

Related Questions