Home>

We are introducing Capistrano in the deployment work of personal development application.
After implementing a set of coding, the following error occurred at the deproy command,
I want to solve it.

Mysql2::Error::ConnectionError: Access denied for user'growool'@'localhost' (using password: NO)
Applicable source code

database.yml

<% require'settings' %>default:&default
  adapter: mysql2
  encoding: utf8
  pool:<%= ENV.fetch("RAILS_MAX_THREADS") {5} %>username: root
  password:
  socket: /tmp/mysql.sock
  host: localhost
development:
<<: *default
  database: growool_development
test:
<<: *default
  database: growool_test
production:
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: growool_production
  username:<%= mysql.database_name %>password:<%= mysql.database_password %>socket: /var/lib/mysql/mysql.sock
  host: localhost


deploy.rb

lock "~>3.14.0"
set :application, "growool"
set :repo_url, "[email protected]:keisuke-kk/growool.git"
# set :branch,'master'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/var/www/rails/growool"
set :linked_files, fetch(:linked_files, []).push('config/master.key')
set :linked_dirs, fetch(:linked_dirs, []).push('log','tmp/pids','tmp/cache','tmp/sockets','vendor/bundle','public/system')
set :keep_releases, 5
set :rbenv_ruby, '2.5.1'
set :log_level, :debug
set :bundle_flags,'--quiet'
set :bundle_path, nil
set :bundle_without, nil
namespace :deploy do
  desc'Restart application'
  task :restart do
    invoke'unicorn:restart'
  end
  desc'Create database'
  task :db_create do
    on roles(:db) do |host|
      with rails_env: fetch(:rails_env) do
        within current_path do
          execute :bundle, :exec, :rake,'db:create'
        end
      end
    end
  end
  desc'Run seed'task :seed do
    on roles(:app) do
      with rails_env: fetch(:rails_env) do
        within current_path do
          execute :bundle, :exec, :rake,'db:seed'
        end
      end
    end
  end
  desc'Config bundler'
  task :config_bundler do
    on roles(/.*/) do
      within release_path do
        execute :bundle, :config,'--local deployment true'
        execute :bundle, :config,'--local without "development test"'
        execute :bundle, :config, "--local path #{shared_path.join('bundle')}"
      end
    end
  end
  after :publishing, :restart
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
    end
  end
end
before'bundler:install','deploy:config_bundler'


capfile

require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require'capistrano/setup'
require'capistrano/deploy'
require'capistrano/rbenv'
require'capistrano/bundler'
require'capistrano/rails/assets'
require'capistrano/rails/migrations'
Dir.glob("lib/capistrano/tasks/*.rake").each {|r| import r}


gemfile

source'https://rubygems.org'
git_source(:github) {|repo| "https://github.com/#{repo}.git"}
ruby '2.5.1'
# Bundle edge Rails instead: gem'rails', github:'rails/rails'
gem'rails','~>5.2.4','>= 5.2.4.3'
# Use mysql as the database for Active Record
gem'mysql2','>= 0.4.4','<0.6.0'
# Use Puma as the app server
gem'puma','~>3.11'
# Use SCSS for stylesheets
gem'sass-rails','~>5.0'
# Use Uglifier as compressor for JavaScript assets
gem'uglifier','>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem'coffee-rails','~>4.2'
# Turbolinks makes navigating your web application faster.Read more: https://github.com/turbolinks/turbolinks
gem'turbolinks','~>5'
# Build JSON APIs with ease.Read more: https://github.com/rails/jbuilder
gem'jbuilder','~>2.5'
# Use Redis adapter to run Action Cable in production
# gem'redis','~>4.0'
# Use ActiveModel has_secure_password
# gem'bcrypt','~>3.1.7'# Use ActiveStorage variant
# gem'mini_magick','~>4.8'
# Use Capistrano for deployment
# gem'capistrano-rails', group: :development
# Reduces boot times through caching;required in config/boot.rb
gem'bootsnap','>= 1.1.0', require: false
group :production, :staging do
  gem'unicorn'
end
group :development, :test do
  # Call'byebug' anywhere in the code to stop execution and get a debugger console
  gem'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem'pry-rails'
  gem'capistrano'
  gem'capistrano-bundler'
  gem'capistrano-rails'
  gem'capistrano-rbenv'
end
group :development do
  # Access an interactive console on exception pages or by calling'console' anywhere in the code.
  gem'web-console','>= 3.3.0'
  gem'listen','>= 3.0.5','<3.2'
  # Spring speeds up development by keeping your application running in the background.Read more: https://github.com/rails/spring
  gem'spring'
  gem'spring-watcher-listen','~>2.0.0'
  gem'pry-byebug'
end
group :test do
  # Adds support for Capybara system testing and selenium driver
  gem'capybara','>= 2.15'
  gem'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem'compass-rails', github:'Compass/compass-rails'
gem'sprockets'
gem'devise'
gem'ed25519'
gem'bcrypt_pbkdf'
gem'settings logic'


application.yml

production:
  mysql:
    database_name: #######
    database_password: #######
    secret_key_base: ###################################
development:
test:
What I tried

・I tried writing the username and password directly to database.yml.
I thought that the password was not properly applied to the variable from the error content.
-The contents of files such as local database.yml were also written to EC2.
I thought it might be referenced during deployment.

Supplementary information (FW/tool ​​version, etc.)

I am using 5.7 with both EC2 and local mysql version.
However, I was using 5.6 when I created the application, and I thought it would be nice during the deployment process, so I upgraded to 5.7.
Because of that,
When you run rails db:create on local, the following error occurs.

LoadError: dlopen(/Users/kandakeisuke/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded :/usr/local/opt/[email protected]/lib/libmysqlclient.18.dylib


I would appreciate it if you could teach me.

  • Answer # 1

    Since I was messing with the settings variously, I will restart the deployment work from 1.

  • Answer # 2

    Since I was messing with the settings variously, I will restart the deployment work from 1.
    Next, I would like to work on the deployment work in another way.

  • Answer # 3

    Since I was messing with the settings variously, I will restart the deployment work from 1.
    Next, I would like to work on the deployment work in another way.