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 password: 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.
Related
I am new to the linux world and I do apologize if this has been asked before, I could not find the answer I need among the answers.
I am running rails 4.2.1 with mysql 5.5.43 with Passenger and Nginx reverse server installed.
I started having problems when I switched to production mode, first it was trying to go to localhost:3000 which is the loopback used for testing. So I started reading online but could not figure out the correct way to set up the config/database.yml to use the correct url for production. I tried and implement several online suggestions but none worked.
If someone could show me the correct way to configure rails to run mysql in development and production include any env variable that I should set. It would be greatly appreciated.
Paul
If you have multiple databases for testing and development, Then you can do something like this.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
I am having trouble connecting my rails app to MySQL. I am using SQL Pro as my GUI.
Heres my database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: ecommerce-app-development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: ecommerce-app-test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: ecommerce-app-production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
I tried creating a database called 'ecommerece-app-developent' in SQL Pro, but heres the error message it gives me:
Connected to host, but unable to connect to database ecommerce-app-development.
Be sure that the database exists and that you have the necessary privileges.
MySQL said: Unknown database 'ecommerce-app-development'
You need to create the database before connecting to it. rake db:create will do this for you, then you can connect to it using SQL Pro or whatever.
I have a problem connecting to DB from my rails app.
I have provided the database.yml file with credentials:
development: &development
adapter: mysql2
encoding: utf8
database: myapp_dev
pool: 5
username: root
password: passoword
test:
<<: *development
database: myapp_test
production:
<<: *development
database: myapp_prod
staging:
<<: *development
database: myapp_staging
But when I try run the app it gives me the following error:
Access denied for user 'root'#'localhost' (using password: NO)
using mysql -u root -p with same credentials I can access my db without issues. can someone tell me what could be a problem here?
EDIT:
I've changed the user from root to some other user but it still gives me the same error. so apparently it uses some other credentials to connect to db.
I ran into the same issue. It turns out it was a mistake in my database.yml file. Here is what my database.yml file looked like:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: !strong_password
host: localhost
port: 3306
pool: 5
timeout: 5000
The ! character at the beginning of the password is not valid YAML markup (for at least what I was trying to achieve). Wrapping quotes ('') around the password fixes the issue. Here is the updated database.yml file:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: '!strong_password'
host: localhost
port: 3306
pool: 5
timeout: 5000
Try the following code, if it works we can go forward
Comment all the previous code in database.yml and paste the following
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_dev
pool: 5
username: root
password: passoword
host: localhost
I'm not familiar with Ruby on Rails, but I have been asked to move a RoR application from one server to another. It all seems to work except I get this log entry in log/production.log:
Mysql2::Error (Access denied for user 'root'#'10.0.0.76' (using password: NO)):
However, in my database.yml file, I'm not using the root user. Here is what it looks like:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: astral
pool: 5
username: some_user_name
password: xyz
host: 10.0.0.76
socket: /tmp/mysql.sock
# 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: astral
pool: 5
username: some_user_name
password: xyz
socket: /tmp/mysql.sock
production:
development
Any idea what I am doing wrong?
I didn't realise this, and now I feel quite stupid. However, maybe someone who is just starting out will be able to save themselves a few minutes of head-bashing by this answer.
It turns out that changes to the database.yml file are only applied once the apache service is restarted/reloaded. Everything is working fine now.
When I type rails server in my CMD the server works and I can go to localhost:3000.
But after i get this messege in the CMD and the same message in the browser on localhost:3000 in the errors section.
Started GET "/rails/info/properties" for 127.0.0.1 at 2010-12-02 21:14:55 +0200
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (30.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (97.0ms)
What is the issue?
here this is 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: mysql2
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: root
password:
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:passwordex
host: localhost
I know you already found the solution to your problem, but I'm going to post this as an answer anyways, for those who might stumble across this same issue.
Having the same exact Access denied for user 'user'#'localhost' (using password: NO) problem, it turns out my database.yml file was malformatted. The reason? YAML doesn't allow certain characters: I happened to be using a '!' in my password, and for whatever reason, the YAML parser reading this database.yml file ignored my password line like it wasn't there, hence the (using password: NO), even though I explicitly declared it.
Solution? Changed my password not to include any YAML special characters. I suppose there might be a way to escape it, though. Annoying nonetheless.
You're using root for your mysql user, but not supplying the root password in config/database.yml.
Incidentally, while its usually ok in development, using the root mysql user in production or for staging is a Very Bad Idea™.
here's a typical mysql config section:
production:
adapter: mysql
database: app_production
username: root
password: password
pool: 5
timeout: 5000
encoding: utf8