0

I know there are a ton of questions and answers related to this question but for all I have tried, it just didn't work for me. When I run my rake tasks such as bin/rake recognize:init or even rake db:prepare or rake db:create, I get the error message below:

Error Log

mac@MacBook-Pro-2 recognize-develop % bin/rake recognize:init
Please require the stackprof gem falling back to fast_stack
Access denied for user 'root'@'localhost' (using password: NO)
Couldn't drop database 'database_name'
rake aborted!
Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: NO)
/Users/mac/Downloads/recognize-develop/lib/tasks/recognize.rake:233:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

/Users/mac/Downloads/recognize-develop/lib/tasks/recognize.rake:233

desc "Initialize Recognize. To be run from fresh install."
  task :init => :environment do
    prevent_production!
    ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = "1"

    Rake::Task['tmp:clear'].invoke
    Rake::Task['db:drop'].invoke # This is LINE 233. It doesn;t go beyond this.
    Rake::Task['db:create'].invoke
    Rake::Task['db:migrate'].invoke

    load "#{Rails.root.to_s}/db/schema.rb" # dont load schema b/c there is some issue with mysql index lengths when done this way
    Rails.application.load_seed

  end

database.yml file

defaults: &defaults
  adapter: mysql2
  username: <%= ENV['DATABASE_MYSQL_USERNAME'] || 'root' %>
  password: <%= ENV['DATABASE_MYSQL_PASSWORD'] || '' %>
  encoding: utf8mb4
  collation: utf8mb4_unicode_ci
  port: 3306
  host: <%= ENV['DATABASE_MYSQL_HOST'] || '127.0.0.1' %>
  variables:
    sql_mode: TRADITIONAL  


development:
  <<: *defaults
  database: <%= ENV['DATABASE_MYSQL_DATABASE'] || 'database_name' %>

Ruby Version ruby 2.7.2p137

Rails Version Rails 6.0.3.7

I have tried everything. I can communicate with my MySQL in the terminal and run query but I get error with this app using MySQL. How can I go about it?

1 Answer 1

1

Maybe you should create a user in the database with sufficient permissions to use it in your application instead of using root.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.