9

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.

medo ampir
  • 1,732
  • 7
  • 30
  • 56

9 Answers9

31

This query solved my problem.

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root@123';
Shabeer K
  • 1,283
  • 16
  • 21
8
  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.

Gass
  • 4,098
  • 2
  • 13
  • 27
5
  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

Samuel Philipp
  • 9,983
  • 12
  • 32
  • 52
Aremu Ibrahim
  • 61
  • 1
  • 5
1

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
shivanisdev
  • 633
  • 6
  • 16
1

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
0

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.

0

Unfortunetly you changes your mysql user or password. If you user/password changed then go to .env file and change your phpmyadmin user and password. Give your database name

DB_DATABASE=hrms
DB_USERNAME=username
DB_PASSWORD=password
Ronny Dsouza
  • 307
  • 1
  • 12
0

Solution is here with 2 step:

Step 1. You have to edit /etc/mysql/my.cnf file and append this setting in mysqld section:

[mysqld]
default_authentication_plugin= mysql_native_password

Step 2. Then run following mysql command:

CREATE USER 'new_root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
GRANT ALL PRIVILEGES ON *.* TO 'new_root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

It is better if you restart your mysql service.

   sudo systemctl restart mysql

This problem happens when you have install mysql8 and your code compatible with mysql5

Amir Hosseinzadeh
  • 5,647
  • 4
  • 17
  • 28
-1

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

Jayjay
  • 92
  • 1
  • 8