Problem when I run my server on localhost (ruby on rails) - mysql

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

Related

How to enable passwordless access to Mysql for Rails?

I have this database config which connects to MySQL database using root without the password. How do I configure MySQL so that all database operations coming from my app will work?
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp
pool: 25
username: root
password:
host: 127.0.0.1
strict: false
possible solution
Answer to this question by chaintng
https://serverfault.com/questions/563714/allow-linux-root-user-mysql-root-access-without-password
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
along with .my.cnf configuration
$ cat ~/.my.cnf
[client]
user=root
password=''
It seems to work, but I am not sure if it is a correct solution.

#<Mysql2::Error: Access denied for user 'root'#'localhost' (using password: NO)>

I get the following error, when trying to generate an app.
I have a database.yml with my db login info, but not sure what this error is exactly. Does anyone know what it is?
I assume it is verify login to the test db.
Make sure that your db username and password are configured for the development environment, not just the test environment. Initial rails application setup is there.
The test database is used by tests, such as rake spec or rake test and the development database is used when you are working with rails such as rails generate or rails console.
A typical setup is below:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: foo_development
pool: 5
username: db_username
password: db_password
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: foo_test
pool: 5
username: db_username
password: db_password
socket: /tmp/mysql.sock
Why do you want to have root user access your application?
It's recommended you create a different user and grant all privileges to this user and then configure your database.yml with those credentials.
I wanted to contribute my answer to this.
It sounds kind of amateur but it may help some poor chap that had the same issue as me.
I had my password in database.yml configured like this:
development:
<<: *default
database: my_db_name
username: my_username
password: !?my_password913
It's a rookie mistake but it screwed me up for a few minutes.
Ensure you wrap your password with quotes if you use special characters because ! for instance would evaluate as a boolean expression of false which would make mysql2 ignore the password field and send password=no
Thanks!

Ruby On Rails: Change database username and password

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.

Rails Project Connection error with MySQL DB - Access Denied for root user

I get this error when running rails with mysql db. Basically it is not giving the root user access. I have no idea why this is and have been stuck with this for a while now.
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: YES)):
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.7ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.7ms)
My Database.yml file is posted below for your reference. Im not sure how i check the password that MYSQL is automatically assigned to? Would it be my computer login password? Anyhow how do i check it. Also i cant simply type mysql on my command line i have to enter the entire path to access it. How do i change it. Most importantly i want to know how this access denied issue can be resolved. Thank you. Using mysql 5.5 on mac. x86_64 build.
# 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: project1_db
pool: 5
user : root
username: root
password: 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: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
Mysql uses the one that you've set on install. Sometimes it's empty.
Try mysql -u root. If it works - remove pass string form database yaml.
If it's not empty - https://stackoverflow.com/search?q=mysql+reset+password

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 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.