The server requested authentication method unknown to the client [caching_sha2_password]

2

I have installed MySQL 8 and Laravel 5.6.18; when I try to execute 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();
        });

I comment: the order of my migrations is correct that is to say 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 migrations without any problem

    
asked by element 15.05.2018 в 16:06
source

1 answer

3

The problem is that it changed the default authentication in MySQL 8, which generates this error.

To solve it, we suggest to execute the following lines, or only the first part of them, depending on the case, obviously you have to replace user and password with the appropriate values:

CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;

CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
    
answered by 15.05.2018 / 16:35
source