5
votes

after installing a new laravel app 5.7 and trying to migrate I get this error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = xxx_db and table_name = migrations)

at C:\xampp\htdocs\xxxxx\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]") C:\xampp\htdocs\xxxxx\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=xxx_db ", "root", "**********", []) C:\xampp\htdocs\xxxxx\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

Please use the argument -v to see more details.

7
already tried that solution but didn't solve my issue.medo ampir

7 Answers

26
votes

This query solved my problem.

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root@123';
5
votes
  1. Re installed MySQL choosing Legacy Authentication Method as shown in iamge attached SQL Authentication method

  2. Database parameters in .env as follows

    DB_CONNECTION=mysql  
    DB_HOST=127.0.0.1  
    DB_PORT=3306  
    DB_DATABASE=database_name  
    DB_USERNAME=database_username  
    DB_PASSWORD=database_password(if any)  
    
  3. Database parameters in config/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', 'database_name'),  
        'username' => env('DB_USERNAME', 'database_username'),  
        'password' => env('DB_PASSWORD', 'database_password'),  
        'unix_socket' => env('DB_SOCKET', ''),  
        'charset' => 'utf8mb4',  
        'collation' => 'utf8mb4_unicode_ci',  
        'prefix' => '',  
        'prefix_indexes' => true,  
        'strict' => true,  
        'engine' => null,  
        'options' => extension_loaded('pdo_mysql') ? array_filter([  
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),  
        ]) : [],  
    ],  
    
  4. Run php artisan migrate from the projects terminal

1
votes

By Providing DB_SOCKET in .env file this issue can be resolved like this :

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=my_db
DB_USERNAME=root
DB_PASSWORD=
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
1
votes

Please Check Server localhost Port on phpmyadmin and .env file like (3306,3307,8889)

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=masterpass
1
votes
  1. Enter to your mysql as root and run this query
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234';

You can change 1234 to be your password

  1. Run these commands

php artisan config:clear

php artisan migrate

Note: this worked for me.

0
votes

You can run Mysql installer - Community (if you are in windows) and then reconfigure mysql server to use legacy authentication method. it should be solve your problem without pain.

-2
votes

Go to your .env file and make sure DB_CONNECTION=mysqland DB connections are correct.