5

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
1
  • 1
    Please add the contents of database.yml (filtering your info) Commented Dec 30, 2011 at 2:25

5 Answers 5

4

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
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @Varun-Vohra! 1. I can connect via terminal using mysql -u the_user -p the_db and run commands like "show tables" just fine. 2. I am new and don't really have my head wrapped around what is the difference between dev and production mode other than dev mode has maybe more error output or info? Seems like the migrations write to the development.log file and the http requests write to the production.log though.. 3. Just tried removing socket: /var/lib/mysql/mysql.sock - same problem still.. 4. Ran gem check mysql2 - there was no output just returned a new line.. so I guess that's ok..
I've added the host attribute to database.yml - still the same error. Basically for some reason the mysql2 gem thinks I'm trying to connect to the database like this "-u root -p"... even though that is not what I have in the database.yml file..
I first removed then added back the socket line and it worked!
1

Ok, I guess this is all part of my learning curve :)

What it ended up being was this: The gem for passenger that I installed originally was version 3.0.9, I did a gem update --system and that installed version 3.0.11. So the server thought it was using version 3.0.11 and I was still pointing to libraries for 3.0.9 in my rails_server.conf file. I found how to upgrade on http://blog.phusion.nl/

1 Comment

Instead of just pointing to Phusion's blog, it would be nice to point to a specific article or to include relevant commands to upgrade Passenger in your actual answer.
0
  1. In Ubuntu 1)/usr/bin/mysql_secure_installation 2) Run in Terminal follow the steps carefully change the mysql password here.Everything done .then go to database.yml change the password previously what u have created. Run rails server and check the application .. it will works

Comments

0

Did you create the database "the_db_I_made"?

First create it, then only run it, else it will show this error continuously.

Now try to tun it.

Comments

0

For Me It was giving error because of no database. So i created one Using :

$ rake db:create

And the problem was solved :D

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.