I have MySQL 8 and Laravel 5.6.18 installed; when I try to run the migrations with:php artisan migrate
An example of my migrations is:
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('nombre')->unique()->index();
$table->string('descripcion', 500);
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->timestamps();
});
Comment: the order of my migrations is correct, that is, first I have the migration users, then categories and then posts
However I get the following error
PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]").
It should be noted that with version 5.7 of Mysql I execute the migrations without any problem
The problem is that you changed the default authentication in MySQL 8, which causes this error.
To solve it, it is suggested to execute the following lines, or only the first part of them, depending on the case, obviously you have to replace
user
ypassword
with the appropriate values:This worked for me:
First I created a new user:
I then configured the config/database.php file ( https://github.com/laravel/framework/pull/23948 ):
And lastly I configured the .env :
Clever!!!
For MySql 8 I have solved it by changing the authentication method in the configuration at the time of the installation process. Staying as follows:
For me the sql command worked
and read the review