前提・実現したいこと
Laravel Framework 5.8.35
MySQL 5.6.45
laravelとMySQLの接続ができません。
php artisan migrateでエラーが表示されました。
http://qiita.com/yoriblog/items/60b7cea4f991b842022f
https://qiita.com/coldsleep6666/items/506fd6a92ff29aee90bb
これらのサイトなど試してみましたが、出来ませんでした。
因みにhomesteadは利用していません。
発生している問題・エラーメッセージ
コマンド上
[vagrant@localhost practice]$ php artisan migrate Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE') at /home/vagrant/laravel_lessons/practice/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory") /home/vagrant/laravel_lessons/practice/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 2 PDO::__construct("mysql:unix_socket=/tmp/mysql.sock;dbname=homestead", "homestead", "secret", []) /home/vagrant/laravel_lessons/practice/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 Please use the argument -v to see more details.
.env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=db_name DB_USERNAME=設定した名前 DB_PASSWORD=設定したパス
database.php
'mysql' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, 'engine' => null, 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], ],
AppServiceProvider.php
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; // ↓mysqlと接続のため追記 use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { // 追記 Schema::defaultStringLength(191); } }
php artisan tinker実行結果
[vagrant@localhost practice]$ php artisan tinker Psy Shell v0.9.9 (PHP 7.1.32 — cli) by Justin Hileman >>> config('database') => [ "default" => "mysql", "connections" => [ "sqlite" => [ "driver" => "sqlite", "url" => null, "database" => "/home/vagrant/laravel_lessons/practice/database/database.sqlite", "prefix" => "", "foreign_key_constraints" => true, ], "mysql" => [ "driver" => "mysql", "url" => null, "host" => "127.0.0.1", "port" => "3306", "database" => "homestead", "username" => "homestead", "password" => "secret", "unix_socket" => "/Applications/MAMP/tmp/mysql/mysql.sock", "charset" => "utf8mb4", "collation" => "utf8mb4_unicode_ci", "prefix" => "", "prefix_indexes" => true, "strict" => true, "engine" => null, "options" => [], ], "pgsql" => [ "driver" => "pgsql", "url" => null, "host" => "127.0.0.1", "port" => "3306", "database" => "homestead", "username" => "homestead", "password" => "secret", "charset" => "utf8", "prefix" => "", "prefix_indexes" => true, "schema" => "public", "sslmode" => "prefer", ], "sqlsrv" => [ "driver" => "sqlsrv", "url" => null, "host" => "127.0.0.1", "port" => "3306", "database" => "homestead", "username" => "homestead", "password" => "secret", "charset" => "utf8", "prefix" => "", "prefix_indexes" => true, ], ], "migrations" => "migrations", "redis" => [ "client" => "predis", "options" => [ "cluster" => "predis", "prefix" => "laravel_database_", ], "default" => [ "url" => null, "host" => "127.0.0.1", "password" => null, "port" => "6379", "database" => 0, ], "cache" => [ "url" => null, "host" => "127.0.0.1", "password" => null, "port" => "6379", "database" => 1, ], ], ] >>>
試したこと
エラーメッセージをコピーし、検索にかけてみましたが分かりませんでした。
初歩的な問題かもしれませんが、どうかよろしくお願い致します。