phpのmigrationに時間がかかった件

$ php artisan make:migration [テーブル名]
$ php artisan migrate

上記の2番目のコマンドを実行するとエラーが発生して、解決するまでにかなりの時間を要した。


[xxxx@localhost:forum]$ php artisan migrate
   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = forum and table_name = migrations)

database.phpにtmp/mysql.sockを追加。

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
            'unix_socket' => '/tmp/mysql.sock', // 新しく追加
        ],



そうすると新たなエラーメッセージが出てきた。

[xxxx@localhost:forum]$ php artisan migrate
   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = yyyy and table_name = migrations)

/etc/my.confにdefault_authentication_plugin= mysql_native_passwordを追加。

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default_authentication_plugin= mysql_native_password



さらに新たなエラーメッセージが出力された。

[xxxx@localhost:forum]$ php artisan migrate

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = yyyy and table_name = migrations)

mysqlのuserテーブルのpluginをcaching_sha2_passwordからmysql_native_passwordに変更。

mysql> UPDATE user SET plugin = mysql_native_password WHERE user = root;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | mysql_native_password |
+------------------+-----------+-----------------------+

mysql起動時のパスワードを設定していなかったので、database.phpにある'password'の行をコメントアウト

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            //'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
            'unix_socket' => '/tmp/mysql.sock', // 新しく追加
        ],



またまた新たなエラーメッセージが出力された。

[xxxx@localhost:forum]$ php artisan migrate
   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1049] Unknown database 'yyyy' (SQL: select * from information_schema.tables where table_schema = yyyy and table_name = migrations)

yyyyというデータベースを作成。

CREATE DATABASE yyyy charset=utf8;

これでようやくphp artisan migrateが成功。ありがとうgoogle先生