Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Just setup a new rails 3.1.3 app using mysql (mysql2 gem) on CentOS 5 server / apache / passenger... I have correctly setup a database and a user for that database and I have added the login and info into my database.yml file... I can generate stuff, and rake db:migrate ok but the "We're sorry, but something went wrong." message is being rendered in the browser and this message is showing up in my production.log file!

Started GET "/" for xx.xxx.xx.xxx at 2011-12-29 19:52:35 -0600

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

weird, I am not using "root" as the login info in database.yml... Any suggestions?

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: the_db_I_made
  pool: 5
  username: the_user_I_made
  password: the_password
  socket: /var/lib/mysql/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: the_db_I_made
  pool: 5
  username: the_user_I_made
  password: the_password
  socket: /var/lib/mysql/mysql.sock
like image 699
webmaster_sean Avatar asked Dec 30 '11 02:12

webmaster_sean


1 Answers

Bunch of questions / suggestions:

  1. Can you connect to the database using the terminal?

    mysql -u root -p
    
  2. Also, have you tried this on development mode? If so, please share the results.

  3. Try removing

    socket: /var/lib/mysql/mysql.sock
    
  4. Is the gem installation correct?

    gem check mysql2
    

EDIT:

There is a lot of difference in development and production mode ( including but not limited to, environment variables like the database connection string, asset pre-compilation, different level of logging, custom debug info on error pages )

** Embarrassing!!**

You have not included the "host" property in your config!

Try this:

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  host: your_host #<----- normally localhost
  database: the_db_I_made
  pool: 5
  username: the_user_I_made
  password: the_password
  socket: /var/lib/mysql/mysql.sock
like image 154
vvohra87 Avatar answered Sep 26 '22 00:09

vvohra87