問題発生状況
railsでポートフォリオを概成し終え、EC2へcapistroへデプロイをしようとしたところエラーが発生しました。
データベースはmysqlです。
聞きたいこと
EC2 へ Capistrano でデプロイしたが、接続先が localhost になっているので RDS のホストアドレスに変更したいです。どこで localhost の設定がされているか分からず、変更できない状況です。
エラーログ
長いためgistの載せました
リンク内容
#試したこと、調べたこと
EC2 から RDS への接続は確認済み。
20210311070026]$ mysql -h エンドポイント -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2799 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
capistroは使わず、EC2上でrails db:migrateを実行してもエラー発生、local環境に接続してしまいエラー出る
20210311070026]$ bundle exec rake db:migrate RAILS_ENV=production rake aborted! Mysql2::Error::ConnectionError: Access denied for user 'root'@'localhost' (using password: NO) /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `new' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `mysql2_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_handling.rb:221:in `retrieve_connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/connection_handling.rb:189:in `connection' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/tasks/database_tasks.rb:238:in `migrate' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/railties/databases.rake:84:in `each' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.3.5/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>' /var/www/sdf_app/shared/bundle/ruby/2.6.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>' /home/kosuke/.rbenv/versions/2.6.5/bin/bundle:23:in `load' /home/kosuke/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace) [kosuke@ip-10-0-0-55 20210311070026]$
database.yml 一部抜粋
production: adapter: mysql2 encoding: utf8mb4 pool: 5 database: sdf_app_production username: root password: <%= ENV['RDS_PASSWORD'] %> host: <%= ENV['RDS_ENDPOINT'] %> socket: /var/lib/mysql/mysql.sock
railsガイドには
ENV['DATABASE_URL'] が優先。その設定がなければ
config/database.yml の設定が読まれる。
とのことですが
herokuにデプロイする以降、ENV['DATABASE_URL']を設定していないためdatabase.ymlが読まれるはず。。。
わかる方いましたらコメント、ご回答よろしくお願いします!
回答1件
あなたの回答
tips
プレビュー