LoginSignup
0
0

[初心者向け]Laravel sailでマイグレーション時にSELECT権限でエラーが出た話

Posted at

[初心者向け]Laravel sailでマイグレーション時にエラーが出た話

目的

  • migrationファイルを作成し、内容を変更後、./vendor/bin/sail artisan migrateを実行するとエラーが出力されたので、解決した方法を記載する

エラー内容

$ ./vendor/bin/sail artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'sail'@'172.19.0.4' for table 'migrations' (Connection: mysql, SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕ 
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

      +27 vendor frames 

  28  artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

エラーの原因

  • データベースユーザー sail に対して migrations テーブルへのSELECT権限がないため、クエリが失敗しているとのこと。

解決方法

  • php myadminのユーザー権限を設定する。
    メニューからユーザーアカウントを選択
    image.png

以下の画像のように設定を変更して保存
image.png

注意

エラーの解決策として .env ファイルの DB_USERNAME を root に変更するという方法がありますが、誤ってデータベースを破壊したり、悪意のあるSQLインジェクションによって被害を受けやすくなるリスクが高まります。開発環境であっても、root ユーザーの使用は最小限に抑えるべきです。

0
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
0
0