###【質問】
1.PDOエラーの解決方法や、考え方・確認方法
2.MySQLの権限でプログラムからテーブルの作成・追加・変更・削除をさせる場合、実際はどのような権限を与えるのか
3.本に書かれている文字コードのための修正の可否
###【現状】
現在Laravelの勉強をしています。
1つ目が、[php artisan migrate]コマンドを実行するとエラーになってしまい、教えていただきたいです。
[ Illuminate\Database\QueryException ]というのが出ており、PDOExceptionらしいのです。
調べてみて、利用するDBに権限を付与してログインができるのですが、Laravelからの接続が出来ていないらしいのです。
2つ目が、この権限付与を実行したのですが権限がたくさんあったため、実際はどの権限を渡せばいいのかわからなかったです。
プログラムからテーブル作成等を行う場合の権限は、どのようなものが必要なのでしょうか?
[GRANT ALL ON entryLaravel.* TO laravel@localhost;]
というのを実行しました。
これで良いのでしょうか?
3つ目が、関係ないと思うのですが読んでいる本だと、Laravel5.4以上は以下のように追記するように書かれていました。
MySQLの文字コードが変更されたためvarcharがあるとエラーになるから。ということのようです。
これも正しいのかわからないのですが、必要なのでしょうか?
###【ローカル環境】
OS: Mac
PHP: 7.2
Laravel: 5.7.13
MySQL: 8.0
読んでいる本: はじめてのLaravel入門
ド素人ですみませんが、どうぞよろしくお願いいたします。
###【+++追記+++】
●ターミナルでのエラー
Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = entryLaravel and table_name = migrations) at ~/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::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]") /Users/snowdog/Desktop/04_acts/00_entryLaravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=entryLaravel", "laravel", "laravel789", []) /Users/snowdog/Desktop/04_acts/00_entryLaravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 Please use the argument -v to see more details.
●php artisan migrationコマンドで出来たファイル
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CrateBookTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->string('item_name'); $table->integer('item_number'); $table->integer('item_amount'); $table->datetime('published'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('books'); } }
回答1件
あなたの回答
tips
プレビュー