3

I am working through a RoR tutorial from lynda.com for a week already & without changing anything today i was not able to see my content on localhost due to this error :

Mysql2::Error Access denied for user 'simple_cms'@'localhost' (using password: YES)

I do know that this problem has been referred many times befored , i am still not able to find a confirmed solution .

To give you further information regarding my set up my working enviroment is Yosemite 10.10.4 - Rails 3.2.22 - 5.6.22 MySQL - WEBrick 1.3.1

i have set up the SQL database as it looks below on the database.yml file on the config folder of the project

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: **********
  socket: /tmp/mysql.sock


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

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

Also i noticed that by trying to connect via terminal on the database with the password

§ mysql -u root -p

and again i get the error ::ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

I tried to restart manually MySQL server from menu & all i got was the same error!

What is the problem and it doesn't let me log in with the settings as i did all this time ?

Is it a problem with rails or with mysql settings?

While everything seems to be as it has to be,do i have to change something on the database.yml file?

geokara1322
  • 60
  • 1
  • 9

3 Answers3

0

The error-message

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

will Show up if you entered a wrong password. Reset your Password according to this link.

Benvorth
  • 7,416
  • 8
  • 49
  • 70
  • Thank you for your reply , i just found out that when i run the command `show databases;` the response does not contain the database `simple_cms_development`.How is this possible to happen by the time i was working on this about a week already? – geokara1322 Aug 08 '15 at 19:16
  • you can easily check if the databse actually exists: In the filesystem go to your mysql/data Folder. Here a Folder for each database is created. Do you see a Folder named `simple_cms_development`? – Benvorth Aug 08 '15 at 19:19
  • Unfortunately it is not referred there anywhere .. What should i do now ? I am even more confused.. – geokara1322 Aug 08 '15 at 19:27
  • when you can run `Show databases` and see a result you can connect to your database. Where you run this comand, run a `create database simple_cms_development`. – Benvorth Aug 08 '15 at 19:29
  • `mysql> create database simple_cms_development; ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'simple_cms_development'` This is the result of this command , does this mean that it actually exists? – geokara1322 Aug 08 '15 at 19:34
  • you are not connected to your database. Reset your Password as described in the link above or in the answer here: http://stackoverflow.com/questions/8838777/error-1044-42000-access-denied-for-user-localhost-to-database-db – Benvorth Aug 08 '15 at 19:43
0

I finally solved this problem by uninstalling the current MySQL via terminal with the command brew uninstall MySQL & then reinstalling it with brew, from the beginning!

After the installation, when i tried to login into MySQL i did it through the command :mysql -u root -p! At this point on the password request i added the one that has been set up before on the config file :database.yml and it logged in succesfully!

Thanks for the help!

geokara1322
  • 60
  • 1
  • 9
  • I have a very similar issue as well when configuring and setting up my app -- also called simple_cms too. :) After you did 'brew install mysql' to reinstall it, did you do anything else or just go with 'mysql -u rails_user -p simple_cms_development then enter the same password you have in database.yml? Because I still get the same password error here. – Codestudio Mar 25 '20 at 08:29
0

You need to do 3 things :

  1. Check if Mysql Server is On(or Started)
  2. Change the password logging in mysql from terminal.
  3. Create a database in your project folder using:

    $ rake db:create

and that should do it for you so it did for me.

Pratik Naik
  • 410
  • 4
  • 13