When I try to run rake db:migrate RAILS_ENV=production I get an error because it tries to connect to localhost (error: Mysql2::Error: Access denied for user 'xxxx'#'10.0.0.7' (using password: NO))
This is my database.yml file:
production:
adapter: mysql2
encoding: utf8
pool: 5
host: long-amazon-aws-rds-instance-endpoint
database: xxxx_production
username: xxxxx
password: <%= ENV['XXXX_DATABASE_PASSWORD'] %>
when I run echo $XXXX_DATABASE_PASSWORD it gives me the correct password and when I run a mysql -uxxxxx -hlong-amazon-aws-rds-instance-endpoint -p and then enter my password I can connect to the RDS no problem. I also have the environment variable set for passenger and the app connects fine to it, so the RDS instance is definitely reachable.
Why is rake trying to use the local ip and not the hostname specified in database.yml
So turns out you have to wrap the production in quotes. If I run rake db:migrate RAILS_ENV="production" it works...
Related
Here is the log
Can't connect to MySQL server on 'remote.ip.here.lol' (110)
Couldn't create 'solicit' database. Please check your configuration.
rails aborted!
Mysql2::Error: Can't connect to MySQL server on 'remote.ip.here.lol' (110)
bin/rails:4:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
my db.yml is like this:
default: &default
adapter: mysql2
encoding: utf8
database: db
host: remote.ip.here.lol
port: 3306
username: admin
password: supressed
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
test:
<<: *default
I don't have any clue of how to start, I recently got hired, my boss told about a gem dotenv-rails but I can't see how it fit to the current issue that I'm curently facing.
Edit: apparently using localhost and local database and user works fine, but not with the remote configuration.
Edit 2: I've created environment variables with dotenv and apparently I only need to fill a .env file with the needed information, it worked.
You might not have MySQL running on your machine? It seems you are trying to connect to your server but MySQL is not up.
I have Openshift RoR app. When I trying to run some rake task which uses DB, it gives me error:
rake aborted!
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
When I pushed my app 1st time there was no socket value in database.yml, I added it later trying to fix this issue, set it to env variable of socket, which is:
"/var/lib/openshift/some_key/mysql//socket/mysql.sock
" In mysql.log I have this same socket too. So I don't understand where is this "/var/lib/mysql/mysql.sock" came from. I guess I need rebuild my app somehow, but it only restarts on "push" now. Or is this wrong idea?
EDIT: Here is my database.yml from .openshift/config. As i mentioned i added "soket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>" later, after first push. I just tried 'force_clean_build' marker, it didn't help though.
development:
adapter: mysql2
database: database
username: root
password: psswd
host: localhost
test:
adapter: mysql2
database: database
username: root
password: psswd
host: localhost
production:
adapter: mysql2
database: "<%=ENV['OPENSHIFT_APP_NAME']%>"
username: "<%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>"
password: "<%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>"
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
soket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>
Turned out server didn't run all necessary rake:db tasks on deploy. That's why I was getting 'We are sorry...' error. And to run rake tasks through ssh, You need to add "RAILS_ENV=production" before it, like this:
RAILS_ENV=production rake db:setup
This 2 problems (not necessarily connected) made it look for me, like there is problem with DB config.
I have did all the procedures as mentioned in several places and I also learned from lynda.com video tutorial. I used Mac 10.7 and I installed rubystack. I created the databases, add and checked the database.yml here is you can see it again.
development:
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
database: simplecmsdevelopment
pool: 5
username: simple_cms
password: maiwandj
socket: /tmp/mysql.sock
Therefore, when I run rake db:schema:dump it print the following errors
bash-3.2$ rake db:schema:dump
/Applications/rubystack-1.9.3-18/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:220: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
rake aborted!
Access denied for user 'simplecms'#'localhost' (using password: YES)
/Applications/rubystack-1.9.3-18/simplecms/config/environment.rb:5:in `' Tasks: TOP => db:schema:dump => environment (See full trace by running task with --trace)
Have you granted permissions for that user on that database? i.e., GRANT ALL PRIVILEGES ON simplecmsdevelopment.* TO simple_cms#localhost;
You'll want to grant permissions on the simplecmsdevelopment database for simple_cms#localhost:
GRANT ALL PRIVILEGES ON 'simplecmsdevelopment'.* TO 'simple_cms'#'localhost';
You might want to change the directory permissions to something like 755 for /usr/local/bin as well... That should fix the warning.
DB yml Config file mentions username: simple_cms, but error message in console mentions user 'simplecms'#'localhost'.... I would suggest you should rewrite db yml configurations. I guess you might be having wrong username 'simplecms' written for test environment.... most probably.... do check...
JRuby 1.7.1 and Rails 3.2.11
In terminal I'm running "rake db:multi:migrate DATABASE=configuration" but I keep getting the error below meaning as far as I can tell that the configuration database is not being created.
Connecting to database specified by database.yml
(4.0ms) SET SQL_AUTO_IS_NULL=0
rake aborted!
The driver encountered an unknown error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'configuration'
The specific steps I'm supposed to follow to get this set up are:
mysql.server start
mysql -uroot
create user 'funapp_test'#'localhost' IDENTIFIED BY 'funapp_test';
grant all privileges on *.* to 'funapp_test'#'localhost' with grant option;
create user 'funapp'#'localhost' IDENTIFIED BY '#sh4r3!';
grant all privileges on *.* to 'funapp'#'localhost' with grant option;
RAILS_ENV=test rake db:create
RAILS_ENV=development rake db:create
mysql -uroot funapp_test < db/structure.sql
mysql -uroot funapp < db/structure.sql
rake db:multi:migrate DATABASE=funapp
rake db:multi:migrate DATABASE=configuration
database.yml
development:
adapter: mysql
database: funapp
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
test: &test
adapter: mysql
database: funapp_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
configuration_development:
adapter: mysql
database: configuration
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
configuration_test:
adapter: mysql
database: configuration_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
Any ideas on what I can do to get this fixed? I've tried doing rake db:drop and rake db:migrate, as well as rake db:create:all (which gives me a Riak::Node configuration must include :source and :root keys. error) Thank you so much!
Figured it out, much simpler than I thought
mysql -uroot
create database configuration;
create database configuration_test;
I have somewhat of a complex issue involving several different programs including redmine, MySQL, Ruby, Ruby on Rails etc. This is on Windows XP.
I am following the redmine instructions here: http://www.redmine.org/projects/redmine/wiki/RedmineInstall
I am on step 5. where I am suppose to type RAILS_ENV=production rake db:migrate
When I type this in the command prompt and hit enter I get an error: "RAILS_ENV" is not a command blah blah.
So I reorder it to: rake db:migrate RAILS_ENV=production
This seems to work correct, but I get the following:
C:\redmine-1.2.1>rake db:migrate RAILS_ENV=production --trace
* Invoke db:migrate (first_time)
* Invoke environment (first_time)
* Execute environment
rake aborted!
Access denied for user 'redmine'#'localhost' (using password: YES)
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `real_connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:203:in `initialize'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:75:in `new'
Here is my database.yml file contents:
MySQL (default setup).
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: ****
encoding: utf8
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password:
encoding: utf8
# 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: mysql
database: redmine_test
host: localhost
username: root
password:
encoding: utf8
test_pgsql:
adapter: postgresql
database: redmine_test
host: localhost
username: postgres
password: "postgres"
test_sqlite3:
adapter: sqlite3
database: db/test.sqlite3
I really need some direction here. It's almost like there is a problem with my users/passwords. I have changed the passwords not to contain "!" or any other special characters. I do have capital and lower case letters.
Any help would be greatly appreciated.
DemiSheep
So, you have created the 'redmine' mysql user with the password specified in database.yml?
Can you connect to this user using mysql client? (e.g. mysql -uredmine -pyourmysqlpassword)
Does the user have all required privileges?