Rails 4 mysql2 error when deploying to production - mysql

I've got an Ubuntu virtual server (Digital Ocean Droplet) set up with Capistrano 3. I've successfully gotten all of the directories set up and the project directory has the current folder in it, containing config/database.yml file. I can't get it deployed to where it will run. It gets stuck on the rake db:migrate phase. rake assets:precompile successfully works, so I think it must be something with my database.yml file. The "production" block looks like this:
config/database.yml (production part)
production:
adapter: mysql2
encoding: utf8
database: capstone_production
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: localhost
port: /var/run/mysqld/mysqld.sock
I have checked that the file is valid YAML with YAMLLint utility. Also, the environment variables echo properly with (root) credentials that I am able to use for mysql login. When I run cap production deploy:check, everything is good. However, running cap production deploy does everything okay until it gets to the rake db:migrate Capistrano process. Then it aborts and throws up this:
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host 107.170.105.223: Exception while executing on host 107.170.105.223: rake exit status: 1
rake stdout: rake aborted!
Mysql2::Error: Access denied for user 'root'#'localhost' (using password: NO)
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `connect'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/gems/mysql2-0.3.20/lib/mysql2/client.rb:70:in `initialize'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/connection_handling.rb:87:in `connection'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/migration.rb:916:in `initialize'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/migration.rb:814:in `new'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/migration.rb:814:in `up'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/migration.rb:792:in `migrate'
/home/deploy/apps/capstone_project/shared/bundle/ruby/2.1.0/bundler/gems/rails-331210df7c8a/activerecord/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
I've tried many combinations of YAML syntax and restarted mysql server, puma server, and NGINX server over and over again. This is crazy, please help.
UPDATE
The problem seems to stem from this:
Mysql2::Error: Access denied for user 'root'#'localhost' (using password: NO)
From what I've read in MySQL docs, this error is thrown when you try to login without password. So I've got all the right credentials - I can even hard code the actual username and password into the YAML file and same error. For some reason when Capistrano executes the following command (via cap production deploy or cap production deploy:migrate), it's not including the password from database.yml:
INFO [85893e95] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate on 107.170.105.223
DEBUG [85893e95] Command: cd /home/deploy/apps/capstone_project/releases/20160205235633 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
How to ensure that Capistrano executes the migration just like I would locally in development?
Thank you

Related

Ruby Mysql can't connect to localhost (10061)

Im following the ruby on rails course from Lynda, where I have problems connecting to the database using the command line in windows.
I can connect to the database using "mysql -u username -p" and entering the password afterwards. I can create databases and all without problem.
Now when executing:
rake db:schema:dump
in my application folder "simple_cms" I get the following:
rake aborted!
Can't connect to MySQL server on 'localhost' (10061)
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)
Running the trace gives:
C:\Users\ASUS\Desktop\simple_cms>rake db:schema:dump --trace
** Invoke db:schema:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:dump
rake aborted!
Can't connect to MySQL server on 'localhost' (10061)
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.
rb:44:in `connect'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.
rb:44:in `initialize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/mysql2_adapter.rb:16:in `new'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:315:in `new_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:242:in `loop'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:242:in `block in checkout'
C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:239:in `checkout'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:102:in `block in connection'
C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:101:in `connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/connec
tion_adapters/abstract/connection_specification.rb:145:in `connection'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/railti
es/databases.rake:379:in `block (4 levels) in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/railti
es/databases.rake:378:in `open'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.2.10/lib/active_record/railti
es/databases.rake:378:in `block (3 levels) in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block i
n execute'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute
'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block i
n invoke_with_call_chain'
C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_
with_call_chain'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `
invoke_task'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `
block (2 levels) in top_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `
each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `
block in top_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `
run_with_threads'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `t
op_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `b
lock in run'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `
standard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `r
un'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>
'
C:/Ruby192/bin/rake:19:in `load'
C:/Ruby192/bin/rake:19:in `<main>'
Tasks: TOP => db:schema:dump
C:\Users\ASUS\Desktop\simple_cms>
Now in my database.yml file I have already put user and password in and remembered to put the integerpassword in "" and a space between the colon and the password itself like:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem '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: simplelogin
password: "1234"
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 have even tried switching the "localhost" with the ip as described here (same problem): Rails development - Can't connect to MySQL server on 'localhost' (10061)
But when I do that I don't get any messages in return from the commandline.
So why can't I connect to the database?
Would appreciate any help! Thanks! Trying to learn ruby and the whole installationsprocess has already eaten up lots of hours...
The problem with using the mysql command and using a connector is that mysql can have different default parameters based on how it is configured, making it difficult to know what is going on.
You should look for a file called my.cnf (or my.ini if you're on Windows). It can specify a different port or host. You're lucky that you are able to connect to the database through mysql because you can see where you are actually connected.
Take a look at your port:
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| socket | /tmp/mysql.sock |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> show variables like 'hostname';
+---------------+-------------+
| Variable_name | Value |
+---------------+-------------+
| hostname | myhostname |
+---------------+-------------+
1 row in set (0.00 sec)
See if these values match up with the database.yml file.
Once you have these values, you can try to telnet on that port. If there is nothing listening on that port you'll get something like:
$ telnet localhost 11111
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host
but if there is a connection, you'll see some junk with "mysql" written somewhere:
$ telnet localhost 3306
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
J
5.5.28JzKEXl7?5e|bUcq/5\Q^mysql_native_passwordConnection closed by foreign host.
I work on Unix, so your output may look different.
I was in the same Lynda course.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: root
password:
host: 127.0.0.1
port: 3306
socket: C:/xampp/mysql/mysql.sock
I'm on Windows 8 and using mysql with the XAMPP package.
I have tried everything, and what really fixed it was the change from localhost to 127.0.0.1
I worked on this issue for a few days, tried nearly every solution available on internet.
Finally I am able to solve that error by adding port:3306 and restarting WEBrick server using 'rails server' command.
Thank you.
I have seen this hideous thing in Ruby and in the command line!
Can't connect to MySQL server on 'localhost' (10061)
If the solutions above doesn't work, I suspect it could be a problem related to the lack MySQL services running. Rails cannot access MySQL, unless you solve the bug of MySQL.
DIAGNOSIS
Before trying the solution below, go to the command line and try to access MySQL once again from the bin folder:
mysql -u username -p
If you get something like this:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
Then try this:
Run the cmd as administrator (if you can't you must consult with your IT representative)
Go to the bin folder in MySQL and install MySQL services using the following command:
mysqld --install
You can receive any of these 2 messages:
The service already exists!
OR
The service was sucessfully installed
Don't close the cmd!
Search for "Services"
Once you've opened "Services" select MySQL and click "start".
From the command line try to access mysql again as unidentified user, as root or as simple_cms.
mysql -u simplelogin -p
If you are successful, then try to run rails again

JRuby on Rails rake db: tasks all abort with jdbc mysql

we are trying to integrate an existing mysql database in our jruby on rails application.
Our client provided us with a bare bone rails skeleton, which was not configured for a sepcific database. We were later provided with a sql database and were asked to integerate it in our application using mysql. We started out by creating a database.yml file with the necessairy information. We then executed the rake db:create command, which resulted in following error message below. Any suggestions on what we're doing wrong? We're helpless. Thx in advance.
$ rake db:create --trace
rake aborted!
undefined method `each' for nil:NilClass
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:15:in `redefine_task'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:23:in `(root)'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:22:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/jdbc/jdbc.rake:234:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/default_loader.rb:6:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:569:in `load_imports'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:508:in `raw_load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/Users/rath_rio/.rvm/gems/jruby-1.6.6#webgrouper/bin/rake:19:in `(root)'
our system specification:
Java SE 6
JRuby 1.6.6
Rails 3.1
we use following gems for our datebase:
gem 'mysql2', '~>0.3.0'
gem "jdbc-mysql", "~> 5.1.13"
gem "activerecord-jdbc-adapter", "~> 1.2.2"
gem "activerecord-jdbcmysql-adapter", "~> 1.2.2"
our database.yml file:
development:
database: webgrouper_development
adapter: jdbcmysql
encoding: utf8
reconnect: true
pool: 5
username: root
password:
host: 127.0.0.1
test:
database: webgrouper_test
adapter: jdbcmysql
encoding: utf8
reconnect: false
pool: 5
username: root
password:
host: 127.0.0.1
production:
database: webgrouper_production
adapter: jdbcmysql
encoding: utf8
reconnect: false
pool: 5
username: root
password:
host: 127.0.0.1
What I can say so far, having run across this while troubleshooting something else and happening to have the relevant source code up, is that this rake task is dying because it is attempting to iterate over the actions for the current task, but the set of actions is nil.
Understanding exactly what was done wrong in the terse and uncommented code in there is difficult. Something is making this incredibly fragile system break down. I have an odd wild guess. What happens if you put "adapter: jdbcmysql" as the first part of each database stanza in your YML, instead of "database: webgrouper_production"?

Rails 3.1 rc4 problem with mysql2

I just installed passenger (apache2) on my ubuntu server to deploy my rails 3.1 rc4 rails app into the wild, and wanted to change from sqlite to mysql.
I installed the necessary ubuntu packages
I updated my Gemfile with the recommended:
gem 'mysql2'
And updated my database.yml file
production:
adapter: mysql2
database: database
username: deploy
password: (***blocked for security reasons***)
socket: /var/run/mysqld/mysqld.sock
pool: 5
timeout: 5000
When I try to create the production database with rake:
rake db:migrate RAILS_ENV=”production” --trace
It gives me a bunch of crazy errors
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
”production” database is not configured
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord- 3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/railtie.rb:69:in `block (2 levels) in <class:Railtie>'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
(And so on)
I have tried install the regular mysql gem, which also didn't work. I have also tried <0.3 of mysql2, but that seemed to lead to an error being thrown complaining about using versions 0.2 with rails 3.1 rc4
I am really stumped :/
have you tried without the quotes around "production" ?
RAILS_ENV=production rake db:migrate

Problem with rake db:migrate -

I am unable to setup my MySQL DB for Ruby on Rails. After setting up the DB and making sure the config/database.yml file match, I am running into the error message below.
U:\Rails\alpha>rake db:migrate --trace
(in U:/Rails/alpha)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Access denied for user 'admin'#'207-237-91-100.c3-0.avec-ubr13.nyr-avec.n
y.cable.rcn.com' (using password: YES)
C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb:
37:in `connect'
C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb:
37:in `initialize'
C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/con
nection_adapters/mysql2_adapter.rb:14:in `new'
C:/Ruby187/lib/ruby/gems/1.8/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/con
nection_adapters/mysql2_adapter.rb:14:in `mysql2_connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:230:in `send'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:230:in `new_connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:238:in `checkout_new_connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:194:in `checkout'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:190:in `loop'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:190:in `checkout'
C:/Ruby187/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:189:in `checkout'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:96:in `connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_pool.rb:318:in `retrieve_connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connectio
n_adapters/abstract/connection_specification.rb:89:in `connection'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/migration
.rb:486:in `initialize'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/migration
.rb:433:in `new'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/migration
.rb:433:in `up'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/migration
.rb:415:in `migrate'
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/railties/
databases.rake:142
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_cal
l_chain'
C:/Ruby187/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_cal
l_chain'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_excep
tion_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_excep
tion_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
C:/Ruby187/bin/rake:19:in `load'
C:/Ruby187/bin/rake:19
I've checked the password about 15+ times and it's correct as far as I can tell.
database.yml file:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: dbname
pool: 5
username: admin
password: pwhere
host: sql.domain.com
Thanks
One way to test this would be to connect to mysql on the command line from the machine where rails lives. Something like
mysql -u admin -ppwhere -h sql.domain.com
You likely will find that you can't connect that way, either. If so, you've probably got a GRANT problem, which is probably due to specifying the wrong host in the GRANT. For example, if the DB and rails reside on the same machine, mysql may think you are connecting from 'localhost', instead of the DNS name of the rails box (or vice versa).
At the outset you may simply want to grant the admin user access to everything:
GRANT ALL ON *.* to 'admin'#'whereever_rails_lives' IDENTIFIED BY 'pwhere'
mysql grant syntax
The trick is often getting 'whereever_rails_lives' right.
You permissions are incorrect. This is such a lame error because it really means two things. 1) you have the wrong password/username combination; also, you cannot connect to mysql which could seriously mean connecting to a gem problem,installation problem. Mysql can get fussy!
From your question, I'm gathering that you're pretty new to all of this. What i would suggest is instead of worry about connecting to MySQL, you start with sqlite. You don't need fulltext search and the other features that lite doesn't provide!
So, let's get started with sqlite3. How?
It's less work. Just make a rails app, and rake db:create and you are done. Then when you need the features of a mysql database you can really know what's going on with the errors in terms of you being familiar with Rails and debugging.

Can't open rails console: production database not configured, establish_connection raises ActiveRecord::AdapterNotSpecified

My app works pretty much perfectly in production – the website part of it, at least. The problem only pops up when I SSH into my VPS and do "rails c RAILS_ENV=production". The console works fine in development mode.
I've had this problem before (or at least one that looks like it) and fixed it by adding "reconnect: true" to database.yml – but it didn't fix it this time around. Here's the start of the error output:
/home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': RAILS_ENV=production database is not configured (ActiveRecord::AdapterNotSpecified)
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/railtie.rb:57:in `block in <class:Railtie>'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
from /home/tour/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers'
And for my production database settings:
production:
adapter: mysql
encoding: utf8
database: tour_production
pool: 5
username: [user]
password: [password]
socket: /var/run/mysqld/mysqld.sock
reconnect: true
I can't get my mind around why it works through passenger, but no luck with the console. Anyway, I'm using Rails 3, Ruby 1.9.2, Passenger and Nginx.
I've been doing some little stuff through Runner, which is annoying. I'd like to get this fixed. So thanks a bunch for any help.
When you are using the console you specify the environment as the first argument rather than as an environment variable. So:
ruby script/console production
will load the production environment.
Your error message is because it is looking for the environment RAILS_ENV=production rather than just production.
The latest Rails 3 way of doing this is simply:
bundle exec rails console -e production
#Shadwell is correct, however if you're after a consistent syntax you can set RAILS_ENV at the beginning like this:
RAILS_ENV=production rails console
I solved with run:
RAILS_ENV=production bundle exec rails c
more detail on link
or
stackoverflow