How to fix FATAL: database "school-grades-project" does not exist - ruby-on-rails

I am upgrading SQLite3 to PostgreSQL so that it can be deployed to Heroku.
Where else do I have to indicate that the database's name is our-school-project?
This is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
timeout: 5000
development:
<<: *default
database: school-grades-project
host: localhost
test:
<<: *default
database: grades_test
host: localhost
production:
<<: *default
database: grades_production
When I issue:
$ rake db:migrate
I get:
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "school-grades-project" does not exist
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:50:in `rescue in postgresql_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:33:in `postgresql_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:84:in `each'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Caused by:
PG::ConnectionBad: FATAL: database "school-grades-project" does not exist
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:84:in `each'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
/Users/saraginsburg/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Does anyone have any suggestions?

Try rails db:create, this will work.

1) Gemfile:
gem 'pg', '>= 0.18', '< 2.0'
2) install pg on your development environment
3) database.yml example:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: corsego_development
test:
<<: *default
database: corsego_test
production:
<<: *default
database: corsego_production
username: corsego
password: <%= ENV['corsego_DATABASE_PASSWORD'] %>
4)
bundle
bundle update
rails db:create db:migrate

Related

Rails cannot connect to mysql server windows 10

I'm trying desperately to connect my new project / any project at all to the mysql2 server. I'm not really sure whether I've correctly installed MySQL server 5.7.21 or not but perhaps someone could advise.
I'm running ruby 2.3, rails 5.0.7 and mysql2 0.5.1. I definitely have mysql2 in my gemfile. I am running this on my 64-bit laptop with Windows 10
Every time I run a rails db:schema:dump from my project file in the command prompt, it shows this error:
C:\Users\MR_ra\Documents\Sites\matt_radin_cms>rails 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
rails aborted!
Mysql2::Error::ConnectionError: Can't connect to MySQL server on 'localhost'
(10061)
C:/Ruby23/lib/ruby/gems/2.3.0/gems/mysql2-0.5.1-x86-mingw32/lib/mysql2/client.rb:90:in `connect'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/mysql2-0.5.1-x86-mingw32/lib/mysql2/client.rb:90:in `initialize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `new'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `mysql2_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:729:in `new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:773:in `checkout_new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:752:in `try_to_checkout_new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:713:in `acquire_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:490:in `checkout'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:883:in `retrieve_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_handling.rb:91:in `connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:241:in `block (4 levels) in <top (required)>'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:240:in `open'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:240:in `block (3 levels) in <top (required)>'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `block in execute'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `each'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `execute'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
C:/Ruby23/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:193:in `invoke_with_call_chain'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:182:in `invoke'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:schema:dump
Currently my databases.yml file is looking like this:
default: &default
adapter: mysql2
host: localhost
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: ***********
password: ***********
My question is also to answer what does the localhost 10061 refer to?
If your databases.yml file only like this which is you shared your question then you update little bit like this
default: &default
adapter: mysql2
host: localhost
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: xxxxxxxxxxx
password: xxxxxxxxxxx
#=> if live server
#=> socket: /var/run/mysqld/mysqld.sock
#=> for developmen
development:
<<: *default
database: project_development
#=> for test
test:
<<: *default
database: project_test
#=> for production
production:
<<: *default
database: project_production
username: xxxxxxxxxx
password: xxxxxxxxxx
then rails db:create
Actually, that is my configuration which already working
Note: If you developing locally and not set any password for mysql then username and password will look like this
username: root
password:
If you use WAMP or XAMPP you must run this before running rails command. The WAMP is recommended for windows.
that means by default username is root and password is empty.
You can by default set up this configuration if you will run this command for creating a Rails project
rails new project_name -d mysql

ActiveRecord::No Database Error Fatal: Role "..."does not exist

I'm working a project collaboratively with others. It is deployed to heroku and it we're using postgresql.
I want to make changes in a local branch and see my changes in the web browser right away.
How can I do this with heroku?
I'm working in Cloud9 development environment and I used to enter "rails s -p $PORT -b $IP" to view my changes in the app, but now when I do that, I get a "no database error."
I've tried googling things but I'm still confused. How can I make changes to an exisiting app and see my changes locally (without pushing to origin/master)? I've never worked with databases before... using the pre-programmed cloud9, things were just working. I'm not sure how to create a separate database for heroku if that's what is needed.
Here is a copy of my database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
# default: &default
# adapter: sqlite3
# pool: 5
# timeout: 5000
# development:
# <<: *default
# database: db/development.sqlite3
# # 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:
# <<: *default
# database: db/test.sqlite3
# production:
# <<: *default
# database: db/production.sqlite3
# FOR HEROKU -- POSTGRES DB SETUP
# UNCOMMENT WHEN WORKING LOCALLY.
development:
adapter: postgresql
database: planit_developement
pool: 5
timeout: 5000
test:
adapter: postgresql
database: planit_test
pool: 5
timeout: 5000
# production:
# <<: *default
# database: db/production.sqlite3
Here is the full trace when I try to migrate:
rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "ubuntu" does not exist
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `rescue in connect'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:913:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
Tasks: TOP => db:migrate

use mysql as persistence motor in ruby on rails

I need to change sqlite to mysql for work with ruby on rails, but as I am a newbie in this, I have a problem
The first that I did was to go a GemFile and include the mysql gem. I am working in local
localhost:3306 using LAMP
source 'https://rubygems.org'
gem 'rails', '3.2.19'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'hirb'
After I configurate the file database.yml
development:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password: strlen12
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password: strlen12
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password: strlen12
socket: /tmp/mysql.sock
but when I try to run rake db:migrate this error is triggered
fernando#fernando:~/ProyectoTicketMaster/TicketMaster$ rake db:migrate
rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `connect'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `initialize'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/model_schema.rb:310:in `clear_cache!'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activerecord-3.2.19/lib/active_record/railtie.rb:103:in `block (2 levels) in <class:Railtie>'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:418:in `_run__875551666__prepare__678451887__callbacks'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/actionpack-3.2.19/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/actionpack-3.2.19/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `instance_exec'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `run'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `each'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `run_initializers'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/application.rb:136:in `initialize!'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/fernando/ProyectoTicketMaster/TicketMaster/config/environment.rb:5:in `<top (required)>'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `block in require'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/application.rb:103:in `require_environment!'
/home/fernando/.rvm/gems/ruby-1.9.3-p547#ticket_master/gems/railties-3.2.19/lib/rails/application.rb:305:in `block (2 levels) in initialize_tasks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Version of Mysql installed in my pc
fernando#fernando:~/ProyectoTicketMaster/TicketMaster$ mysql --version
mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (i686) using readline 6.2
Check the socket path for MySQL in your file my.cnf (usually in the /etc/mysql/ folder) :
socket=/var/lib/mysql/mysql.sock
you can check if mysql is running with the following command:
mysqladmin -u root -p status
If you make any changes make sure you restart your server. Also you could use the localhost connection:
development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
host: 127.0.0.1
port: 3306

Ruby On Rails Mysql Access Denied

Im trying to excute the following command on a new rails project on my Ubuntu Server.
rails g scaffold User email:string username:string
but Im receiving the following error:
"/usr/local/rvm/gems/ruby-1.9.3-p392/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect': Access denied for user 'root'#'localhost' (using password: YES) (Mysql2::Error)
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/rails/membershipServices/config/environment.rb:6:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/application.rb:103:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have tried accessing mysql thru my server with the credentials provided in database.yml and I can login just fine. But for some reason I can't do it via Ruby on Rails command. My database.yml is:
# 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: membershipServices_development
pool: 5
username: root
password: ******
socket: /var/run/mysqld/mysqld.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: membershipServices_test
pool: 5
username: root
password: ******
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: membershipServices_production
pool: 5
username: root
password: ******
host: localhost
socket: /var/run/mysqld/mysqld.sock
Again I verified that username and password provided was correct by logging into mysql via terminal on my server. Thanks for your help in advance!
I was doing some more research on this website and was able to try different things. The only thing that helped me was renaming the username to root1 root2 and root3 to verify which environment it was using. After doing so I verified Development was being used. I added Host: localhost to my Development connection information and that did the trick.

Trouble installing gitlab-5.0 - rake aborted

Trouble installing gitlab-5.0
https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md#initialise-database-and-activate-advanced-features
root#ubuntu:/home/gitlab/gitlab# bundle exec rake gitlab:setup RAILS_ENV=production
rake aborted!
Access denied for user 'root'#'localhost' (using password: YES)
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:308:in `clear_cache!'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb:104:in `block (2 levels) in <class:Railtie>'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__807030537706508428__prepare__2182945095053453794__callbacks'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/gitlab/gitlab/config/environment.rb:5:in `<top (required)>'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/backports-2.6.7/lib/backports/tools.rb:314:in `require'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/backports-2.6.7/lib/backports/tools.rb:314:in `require_with_backports'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
Tasks: TOP => gitlab:setup => environment
(See full trace by running task with --trace)
Some idea?
If you are following the tutorial and followed the steps for the MySQL database setup then you have configured the database to use gitlab for the user name.
# Create a user for GitLab. (change $password to a real password)
mysql> CREATE USER 'gitlab'#'localhost' IDENTIFIED BY '$password';
but if your database.yml file is attempting to log into the database using the root credentials.
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
username: root
password: "secure password"
# host: localhost
# socket: /tmp/mysql.sock
That is why you would see that error.
Change your database.yml file to reflect the login created in the database setup portion of the tutorial.
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
username: gitlab
password: "$password"
# host: localhost
# socket: /tmp/mysql.sock
That section Initialise Database and Activate Advanced Features is:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
That means you are supposed to execute that command as git, not as root (which hasn't been granted access to the database).
Make sure though that your database.yml config file looks like this one (if you have mysql installed and want to use a mysql database).
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
username: root
password: "secure password"
# host: localhost
# socket: /tmp/mysql.sock
It does declare an access for an account root, but this is purely a declarative mysql account (nothing to do with the user root)

Resources