LoginSignup
1
1

More than 3 years have passed since last update.

SQLSTATE[HY000] [1045] Access denied for user エラー

Last updated at Posted at 2020-06-18

http://localhost:8888にアクセスし、MySQKのデータをlaravelのDBクラスを使って表示するときにでたエラー

実際に出たエラー

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel-project and table_name = migrations and table_type = 'BASE TABLE')

エラーを出してしまった理由

ターミナル からアクセスしていたmysqlのsocketが必要なのにphpmyadminのsocketを.envのDB_SOCKETに記述してしまっていた。

解決した方法

mysqlコマンドの\sでサーバー情報を表示してsocketを.envのDB_SOCKETにコピーし、
ターミナルに戻り、(一度設定した.envを再編集した場合は)キャッシュをクリアにする
$ php artisan config:cache

参考サイト

MySQLサーバー情報取得
https://phpjavascriptroom.com/?t=mysql&p=info

1
1
1

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