2
1

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 3 years have passed since last update.

【エラー備忘録】ブラウザでSQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost'

Posted at

状況

phpのローカルサーバーを立ち上げ、ブラウザでlocalhost:8000へアクセスした時、ブラウザにエラーが表示された。

エラー文

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost'

MySQLへrootユーザーでログインできていないらしい。

原因

ターミナルでMySQLへ下記コマンドでログインしてみる。

$ mysql -u root -p
Enter password: 

パスワードを求められ、「パスワードA(仮)」を入力するとログインできた。

laravelの.envファイルを見てみる。

DB_USERNAME=root
DB_PASSWORD=パスワードB(仮)

.envファイルで設定しているパスワードが異なっていた。

解決法

.envファイルのDB_PASSWORDを「パスワードA(仮)」に書き換える。
ローカルサーバーを再起動すると、無事画面が表示できた。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?