Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am somewhat new to Rails, and much of my experience involves me feeling out how to work out the problem so I apologize in advance if I have missed and obvious solution. I run a Windows machine.

I am creating a log-in and registration using mysql2. MySQL installer has already been used to install the server, workbench, etc. (I configured the root password as password) and I have already installed the mysql2 gem.

The rails was bundled successfully but when I entered rake db:create, the error Access denied for user 'root'@'localhost' (using password: NO) occurred.

Rails then prompted me for my password, I entered it but the error occurred again. After entering my password the second time, it seemed as if it worked fine until I tried to do a rails db:migrate wherein the error appeared again making it not possible to migrate.

This confuses me because in the MySQL query, I have my password set as the same one I entered. I tried giving the 'root' user all the schema privileges, but that made no difference. Please tell me how to solve this problem and thank you.

If you have any questions about my question, please ask.

like image 865
spongezh22 Avatar asked Feb 12 '14 05:02

spongezh22


2 Answers

for me helped

$ mysql -u root -p

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword')

and in databse.yml

development:
adapter: mysql2
database: mydb
host: localhost
username: root
password: "mypassword" #I had an empty string here before

thanks to @spongezh22

like image 178
zombie_ghast Avatar answered Sep 19 '22 19:09

zombie_ghast


seems like your user cannot connect to the mysql DB, try this commands in your console

mysql -u root -p

and when prompted give the password as 'admin'

if this is possible then you should be good to go

And you database yml file should be like

development:
 adapter: mysql2
 database: mydb
 host: localhost
 username: root
 password: mypass
like image 36
Bharat soni Avatar answered Sep 19 '22 19:09

Bharat soni