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
Related
I've been trying to get this figured out for two days now. Any help would be appreciated. I'm trying to just make a sample app using mysql, and rails. But, every time I try to rake db:migrate I get a no access error. I've checked my database.yml file 100 times, and everything looks right. Logging into mysql through the terminal with the exact same login credentials works fine. It seems like mysql is working for everything except for Rails.
default: &default
adapter: mysql2
encoding: utf8
host: localhost
port: 3306
database: my_ror
pool: 50
username: root
password: password
socket: /opt/lampp/var/mysql/mysql.sock
development:
adapter: mysql2
encoding: utf8
host: localhost
port: 3306
database: my_ror_development
pool: 50
username: root
password: password
socket: /opt/lampp/var/mysql/mysql.sock
What am I doing wrong?
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.
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.