LoginSignup
3
0

More than 3 years have passed since last update.

Rails6 Access denied for user 'root'@'localhost' (using password: NO)のエラー

Posted at

目的

  • 記事名のエラーが出た時の筆者の解決方法をまとめる
  • とりあえずエラーを回避する方法をまとめる、MySQLのrootパスワードをRailsの設定ファイルに直接記載するので個人プロダクト以上のアプリでは本方法はオススメしない。

筆者の環境

  • Rails version
    • 6.0.2.1
  • MySQL vsersion
    • Ver 8.0.18 for osx10.13 on x86_64 (Homebrew)
  • OS
    • macOS 10.13.6

手順概要

  1. MySQLのrootパスワードを確認
  2. RailsのDB設定ファイルにMySQLのrootアカウントのパスワードを入力
  3. 接続確認

手順詳細

  1. MySQLのrootパスワードを確認
    1. すでに知っている方はこの手順は飛ばす。
    2. パスワードを失念した場合は下記の方法に従いパスワードを再設定する。
  2. RailsのDB設定ファイルにMySQLのrootアカウントのパスワードを入力

    1. 下記のファイルを開く
      • アプリ名ディレクトリ/config
        • database.yml
    2. パスワードを追加する。

      • password:の後ろにMySQLのrootアカウントのパスワードを記入する。

        # MySQL. Versions 5.5.8 and up are supported.
        #
        # 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:
        #   https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
        #
        default: &default
          adapter: mysql2
          encoding: utf8mb4
          pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
          username: root
          password: 
          host: localhost
        
  3. 接続確認

    1. $ rails sなどを実行してローカル環境でエラーが出ないか確認する。
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0