Ruby on rails mysql problem
I'm creating my first ROR application. Details:
creating new app ->
rails new simple_cms -d mysql
creating a controller and a corresponding view -->
rails generate controller demo index
Then when after i started the rails server, the http://localhost:3000 page works perfectly fine. but when i try to go to the page that I just created, http://localhost:3000/demo/index, it spurts out a MYSQL error:
Access denied for user 'root'@'localhost' (using pass开发者_如何学运维word: NO)
At first, I think it's just a database connection problem, so I've gone through the MYSQL interface and create a new database called: simple_cms_development
and I have also made a corresponding user: simple_cms
with granted privileges.
and lastly, I have configured the database.yml file to fit the details:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: developer
host: localhost
But still, it spits out the same mysql problem: Access denied for user 'root'@'localhost' (using password: NO)
Please. to anyone who knows how to use mysql as a database for rails app..A help would be really appreciated. Thank you so much!
UPDATE: This is all what's inside on the database.yml file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: root
password: developer
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:
host: localhost
I found that you need to add the following line to config/database.yml
:
host: localhost
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
Only reason that can cause your issue is that you are loading your server with different environment. I think that in your case you are loading your server under production mode.
精彩评论