teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

2021/11/02 15:51

投稿

yren
yren

スコア5

title CHANGED
@@ -1,1 +1,1 @@
1
- php artisan migrate実行時にcould not find driverというエラーが出るのを解決したい
1
+ php artisan migrate実行時にSQLSTATE[HY000] [1045] Access denied for user というエラーが出るのを解決したい
body CHANGED
@@ -90,7 +90,7 @@
90
90
  この表示になっています。
91
91
 
92
92
  調べてみると、こういう場合は.envやconfig/database.phpなどでmysqlの設定を変更すると解決すると
93
- 書いてあったのですがその通りやっても上手くいきせんでした。
93
+ 書いてあったので、編集後pho artisan config:cacheを実行しましたが同じエラーメッセージが出力されました
94
94
 
95
95
  [参考サイト](https://qiita.com/miriwo/items/d9b3e00471178b09c0c6)
96
96
 

1

情報追加

2021/11/02 15:51

投稿

yren
yren

スコア5

title CHANGED
File without changes
body CHANGED
@@ -70,4 +70,45 @@
70
70
  Ubuntu 20.04
71
71
  PHP 7.4.25
72
72
  Laravel 8.29.0
73
- MySQL 8.0.27
73
+ MySQL 8.0.27
74
+
75
+ ###追加情報
76
+ 下記のリンクを参考に
77
+ ```
78
+ sudo apt-get install php7.4-mysql
79
+ ```
80
+ を実行してみたところ、「could not find driver」のエラーはなくなりました。
81
+
82
+ [「could not find driver(SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')” Code Answer’s」](https://www.codegrepper.com/code-examples/sql/could+not+find+driver+%28SQL%3A+select+%2A+from+information_schema.tables+where+table_schema+%3D+laravel+and+table_name+%3D+migrations+and+table_type+%3D+%27BASE+TABLE%27%29)
83
+
84
+
85
+ しかし新たなエラーメッセージが表示されました。
86
+ ```
87
+ SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')
88
+ ```
89
+ ここに書いてあるようなforge@localhostというMySQLユーザーは作成していないのですが、
90
+ この表示になっています。
91
+
92
+ 調べてみると、こういう場合は.envやconfig/database.phpなどでmysqlの設定を変更すると解決すると
93
+ 書いてあったのですが、その通りやっても上手くいきませんでした。
94
+
95
+ [参考サイト](https://qiita.com/miriwo/items/d9b3e00471178b09c0c6)
96
+
97
+ ```php
98
+ // config/database.php変更後
99
+
100
+ 'pgsql' => [
101
+ 'driver' => 'pgsql',
102
+ 'url' => env('DATABASE_URL'),
103
+ 'host' => env('DB_HOST', '127.0.0.1'),
104
+ 'port' => env('DB_PORT', '5432'),
105
+ 'database' => env('DB_DATABASE', 'troc'), // 変更
106
+ 'username' => env('DB_USERNAME', 'root'), // 変更
107
+ 'password' => env('DB_PASSWORD', ''),
108
+ 'charset' => 'utf8',
109
+ 'prefix' => '',
110
+ 'prefix_indexes' => true,
111
+ 'schema' => 'public',
112
+ 'sslmode' => 'prefer',
113
+ ],
114
+ ```