6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravelのマイグレーション時にAccess denied for user 'root'@'localhost'になる

Last updated at Posted at 2019-07-02

環境

  • Ubuntu 18.04(WSL)
  • Larave5.8
  • PHP7.2
  • MySQL5.7
.env
DB_DATABASE=laravel58
DB_USERNAME=root
DB_PASSWORD=
bash
php artisan migrate --seed

これをやると次のエラーが出ました。

Illuminate\Database\QueryException  : SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = larave58 and table_name = migrations and table_type = 'BASE TABLE')

調べてる見ると

Turns out you can't use the root user in 5.7 anymore without becoming a sudoer. That means you can't just run mysql -u root anymore and have to do sudo mysql -u root instead.

引用元:SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

mysql5.7はsudoじゃないとrootでログインできないようです。

なのでUbuntuにphpmyadminをインストールした時に作ったphpmyadminというアカウントに権限を与えることにしました。

mysql
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

.envを修正

.env
DB_DATABASE=laravel58
DB_USERNAME=phpmyadmin
DB_PASSWORD=password

これでできました。

参考

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?