15

I created a new Rails project, I used scaffold and then tried to:

rake db:create 

I didn't changed config/database.yml so password was empty (I always enter the password I use to log in to localhost/phpmyadmin but this time I forgot it).

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: test_associations_development
  pool: 5
  username: root
  password: 
  socket: /tmp/mysql.sock

So, back to terminal I had the following message:

$ rake db:create
Access denied for user 'root'@'localhost' (using password: NO). 
Please provide the root password for your mysql installation

>******* (I entered my password here)

$ rake db:create rake aborted!
(<unknown>): couldn't parse YAML at line 31 column 2

Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

After this, I cannot login to phpmyadmin and when I run my apps locally I'm getting this error:

Mysql2::Error

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

I'm using OS X 10.7.2, Rails 3.2, Ruby 1.9.3.

Any ideas?

2 Answers 2

10

You might try and access MySQL using the Terminal.app. At the command line run:

mysql -u root

if you expect the root password to be blank and yet see this:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

You know the password has been changed.

Sounds like the root password has been changed. If you do not know what it is, follow these instructions to reset the password:Resetting MySQL password.

2
  • 4
    Problem solved using the following commands: mysql -u root (no password needed) SET PASSWORD FOR 'root'@'localhost' = PASSWORD('myPassword'); Thank you!
    – Webspirit
    Feb 15, 2012 at 23:07
  • in my case what happened is: there were two passwords - one for dev db and one for test db, i forgot to change the password for test db, ran rake, and it changed the password for my user to test password in the yml file. Sep 29, 2017 at 7:32
3

This answer is in connection with Ruby on Rails framework where this behavior occurred

  1. have mysql with user root and password
  2. bootstrap new rails project using with mysql "rails new projectname
    -d mysql"
  3. do not modify config/database.yml - defaults credentials for server are name: root, password is blank
  4. rake db:create prompt show up - asking for root password and then when you provide root password

the answer is in GRANT command on line 68 in here

basically it executed GRANT command with credentials matches your current database.yml

I have discussed this topic and behavior will improved and it is taken and reported as a bug.

1
  • 1
    Plus +1 for "defaults credentials for server are name: root, password is blank"
    – cameck
    Feb 6, 2017 at 21:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.