Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to fix the infamous "Access denied" error, but I don't understand why my fix doesn't work. Can someone please help me?

EDIT: This is the sequence of steps I took to fix the problem. It is still not working. Can anyone tell me what I'm doing wrong?

$ sudo service mysql stop
mysql stop/waiting
$ sudo service mysql start
mysql start/running, process 5718
$ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
[1] 5758
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 5.5.32-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> UPDATE mysql.user SET Password=PASSWORD('test')
    -> WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4  Changed: 0  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

$ rake db:create
Access denied for user 'root'@'localhost' (using password: NO)Please provide the root password for your mysql installation
share|improve this question
    
Does the rake program supply the root password ('test') to mysql when it tries to create a database? You have changed the password in MySQL but I guess you haven't informed rake about it. –  ypercube Oct 13 '13 at 8:05
    
See this: Why my rake db:migrate throws error message? –  ypercube Oct 13 '13 at 8:11
add comment

1 Answer

This isn't a database problem at all. The tipoff is the "using password: NO" in the error message. Ensure that you're sending a password in your authentication as follows:

Command line

The correct syntax for the CLI client is:

$ mysql -uroot -ptest

Or you can just use -p (with no value), which will prompt you for a password. Note that there's no space between the flag (-u/-p) and the value (myuser/mypassword).

Rails

In your database.yml file, you should have:

adapter: mysql
database: my_db
hostname: 127.0.0.1
username: root
password: test
socket: /tmp/mysql.sock
pool: 5
timeout: 5000

Running rake db:create should now properly create your database.

See: ruby – How do I set up the database.yml file in Rails?

share|improve this answer
    
Hi, can you please look at my edit? Thanks. –  dtgee Oct 13 '13 at 5:32
    
After the edit, you're now asking a completely different question. I've updated my answer. –  Mikkel Oct 13 '13 at 8:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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