[したいこと]
LaravelからMysqlに接続できるようにしたい。
[困っていること]
現在HomesteadでLaravelを使用しているのですがphp artisan migrateを
行った時に下記のエラーが出力されてしまいました。
artisan
1vagrant@homestead:~/code/Twitterpoi$ php artisan migrate 2 3 Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE') 4 5 at /home/vagrant/code/Twitterpoi/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 6 665| // If an exception occurs when attempting to run a query, we'll format the error 7 666| // message to include the bindings with SQL, which will make this exception a 8 667| // lot more helpful to the developer instead of just the database's errors. 9 668| catch (Exception $e) { 10 > 669| throw new QueryException( 11 670| $query, $this->prepareBindings($bindings), $e 12 671| ); 13 672| } 14 673| 15 16 Exception trace: 17 18 1 PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)") 19 /home/vagrant/code/Twitterpoi/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 20 21 2 PDO::__construct() 22 /home/vagrant/code/Twitterpoi/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 23 24 Please use the argument -v to see more details.
原因を調べてみた時に上記のエラーはroot@localhostのアクセスが拒否されたというエラーであることはわかりました。なのでdatabase.phpと.envファイルを編集して接続できるようにすればいいと書いてあったのですが接続が出来ませんでした。。。
databasephp
1'mysql' => [ 2 'driver' => 'mysql', 3 'url' => env('DATABASE_URL'), 4 'host' => env('DB_HOST', '127.0.0.1'), 5 'port' => env('DB_PORT', '3306'), 6 'database' => env('DB_DATABASE', 'laravel'), 7 'username' => env('DB_USERNAME', 'root'), 8 'password' => env('DB_PASSWORD', ''), 9 'unix_socket' => env('DB_SOCKET', ''), 10 'charset' => 'utf8mb4', 11 'collation' => 'utf8mb4_unicode_ci', 12 'prefix' => '', 13 'prefix_indexes' => true, 14 'strict' => true, 15 'engine' => null, 16 'options' => extension_loaded('pdo_mysql') ? array_filter([ 17 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 18 ]) : [], 19 ],
env
1DB_CONNECTION=mysql 2DB_HOST=127.0.0.1 3DB_PORT=3306 4DB_DATABASE=laravel 5DB_USERNAME=root 6DB_PASSWORD=
上記のdatabase.phpと.envファイルはデフォルトの設定です。
[試したこと]
直接Mysqlに接続してみましたがログインができずatabase.phpと.envファイルにもpasswordがないため空欄でログインしたり、確かデフォルトのpasswordはrootだった気がしたのでrootを入力したりしましたがダメでした。
HomesteadはデフォルトでMysqlがインストールしてあるのでそこらへんの設定がどうなっているか全然わかりませんでした。database.phpと.envファイルの設定をきちんとすればphp artisan migrateができるとは思うのですがどうしたらいいかわかりません。。。よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー