rake db:create password authentication fails for user - ruby-on-rails

While running the command rake db:create, the system throws postgresql authentication fails
FATAL: password authentication failed for user "postgres"
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "username"=>"postgres", "password"=>"password", "timeout"=>5000, "host"=>"localhost", "database"=>"rails-sample-guestbook-master_development"}
rake aborted!
database.yml file
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: supranimbus
password: 123456789
timeout: 5000
host: localhost
development:
<<: *default
database: rails-sample-guestbook-master_development
test:
<<: *default
database: rails-sample-guestbook-master_test
production:
<<: *default
database: rails-sample-guestbook-master_production

I guess the problem is setup password on postgresql if you don't remember the default password then go to pgAdmin click to open dashboard and then the left sidebar see the below image
Click the Properties... then will open a modal like see the below image
and click the Definition tab and see the Password field and set the new password, remember this password for postgres username.
That's is for password setup!
Now update your database.yml file like below
default: &default
adapter: postgresql
encoding: unicode
username: postgres
password: 123456 #=> which you set for postgres
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: project_development
Hope to help

Related

rails 5 app generated with postgresql - what's my password?

I have created a Rails 5.0.2 app with postgres as the database, it all works fine in the development environment.
But when I try to test the app in the production environment (Still on my local machine) I just can't figure out what the password for the database is.
I see this error in the log:
PG::ConnectionBad (FATAL: Peer authentication failed for user "myapp"
My database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
Can I access the ENV['MYAPP_DATABASE_PASSWORD'] somehow? Was I supposed to set it up when I created the app?
I realize this may be very trivial. Thanks.

Mysql Connection adapter error

I tried running db:migrate on my app and I'm getting this error.Not sure what is the cause.
My database is MySQL
using MySQL 64-bit connector
ruby version:ruby 2.2.6p396 (2016-11-15 revision 56800) [i386-mingw32]
I've done a google search and I'm not getting anything..Can anyone explain this error pls?
NotImplementedError: NotImplementedError
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:85:in exec_query'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:377:in 'select_prepared'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:39:inselect_all'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in select_all'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/querying.rb:39:infind_by_sql'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/relation.rb:702:in `exec_queries'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-12.0.0/exe/rake:27:in <top (required)>'
C:/RailsInstaller/Ruby2.2.0/bin/rake:23:inload'
C:/RailsInstaller/Ruby2.2.0/bin/rake:23:in `'
Tasks: TOP => db:
migrate
You can try this..
Check your config/database.yml file.
your config/database.yml must look like and username, password should be change your mysql's username, password..
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: username
password: password
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: uBuild-rails_development
test:
<<: *default
database: uBuild-rails_test
production:
<<: *default
database: uBuild-rails_development
username: username
password: password
Also check you Gemfile
gem 'mysql2', '< 0.3' # as stated above
I had the same problem, what I did was to create the project again using this command:
rails new my_project -d=mysql
This way the configuration in database.yml and gemfile is created automatically avoiding problems. You only need to edit database.yml mysql password after this you can use
rails g scaffold Examples attrib1:string attrib2:string
to create views etc
rake db:create
to create the database and then
rake db:migrate
hope this helps...
Database file is in config/database.yml and configuration be
default: &default
adapter: mysql2 #if use postgres the add postgresql
pool: 5
timeout: 5000
username : username #mysql username
password : password #mysql password
development:
<<: *default
database: application_name
test:
<<: *default
database: application_name
production:
<<: *default
database: application_name
Run following command to setup database:
run rake db:create
run rake db:migrate

Staring Rails App With Postgresql - PG::ConnectionBad

I Cannot get the welcome screen not matter what I do, all I get is the connection issue with the postgres db error.
I ran this command to start the app.
rails new -T appName --database=postgresql
Here is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
adapter: postgresql
encoding: unicode
database: dbname
pool: 5
username: toolshiring
password: toolshiring
host: localhost
port: 5432
production:
<<: *default
database: toolshiring
username: toolshiring
password: <%= ENV['toolshiring'] %>
I used pgAdmin to add a user with full permissions named toolshiring and has the same password. Then created the database with owner toolshiring.
I decided to try something and it seems to have worked for the time being.
I decided to reset the password for the default db 'postgres' to the password 'postgres' as well, and delete the new db that I created....because the wasn't working for some reason.
in my database.yml file i commented everything but this
development:
adapter: postgresql
encoding: unicode
database: postgres
pool: 5
username: postgres
password: postgres
host: localhost

Rails Console, Password needed to create new record

I am currently trying to complete a tutorial on ruby on rails and have had this error within IRB when I enter "subject = Subject.new"
Mysql2::Error: Access denied for user 'simple_cms'#'localhost' (using password: YES)
is there a way to supply this to irb when i run
rails console
What is the best way to resolve this?
database.yml is below:
default: &default
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
pool: 5
username: simple_cms
password: mypasshere
socket: /tmp/mysql.sock
development:
<<: *default
database: simple_cms_development
<<: *default
database: simple_cms_test
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
Much appreciated for any help!

How to prevent creation of development.sqlite3 file?

I changed my database.yml file to use postgresql instead of sqlite3.
But when I do rake db:migrate - development.sqlite3 file gets created.
Here's my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
development:
<<: *default
database: scrumban_development
test:
<<: *default
database: scrumban_test
production:
<<: *default
database: scrumban_production
username: scrumban
password: <%= ENV['scrumban_DATABASE_PASSWORD'] %>
Don't include the sqlite3 gem and it should stop creating it.

Resources