Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nickdavies07's avatar

[caching_sha2_password] error when running php artisan migrate

Having an issue, hopefully someone can help as I'm tearing my hair out with this one.

Running the command php artisan migrate in terminal throws the following error:

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

  at /Users/nickdavies07/Sites/office-365-portal/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/nickdavies07/Sites/office-365-portal/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=office_365_portal", "root", "mypassword", [])
      /Users/nickdavies07/Sites/office-365-portal/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  Please use the argument -v to see more details.
nickdavies07 ? (master) 

I have brew installed php 7.2, MySQL 8.0.11 and am running Valet.

Tried resetting the root password which didn't make a difference.

0 likes
12 replies
mibou520's avatar
mibou520
Best Answer
Level 14

Hi Nick,

You can change the encryption of the user's password by altering the user with below Alter command :

  1. mysql -uroot -p

  2. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

It is a walk around because the caching_sha2_password is not supported wet.

So, my understanding (may not be right) is that by upgrading to mysql 8.0, it upgraded the password encrypting to caching_sha2_password. Because Laravel doesn't support it wet (and Sequel Pro in my case) wy need to use the hold encryption.

Thank you

14 likes
joshuajr's avatar

I'm having the same issue but this is not working for me. Using valet and brew installed mysql 8

I get this (though I know the mysql server is running and can log in on the command line or workbench using same credentials)

[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away

[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away

[PDOException] PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

Jaikangam's avatar

I was getting error in the production server while php artisan migrate

In connection.php line: 664

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables whe re table_schema = prod and table_name = migrations)

In connection.php line: 70 SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

After running the @mibou520 comment on myslq it is working fine for me. Thanks ...

1 like
vishav's avatar

I had the same problem today. The only way I found the fix for it was:

1.Executing the re- install setup file 2.Select "Reconfigure" over the mysql server

  1. Go through the normal installation process until you reached authentication 3.Do not use their recommended authentication type 4.In Authentication Method tab, select "Use Legacy Authentication Method" i.e second option for convenience

Go to your laravel project and type command php artisan config:clear run -> php artisan migrate

You are good to go ..! Thank me later :)

iamjekayode's avatar

Alternatively, according to this fix, you can just modify your database.php file if you are using MySQL 8.x :

// database.php

    'connections' => [

        'mysql' => [
            'driver'      => 'mysql',
            'host'        => env( 'DB_HOST', '127.0.0.1' ),
            'port'        => env( 'DB_PORT', '3306' ),
            'database'    => env( 'DB_DATABASE', 'forge' ),
            'username'    => env( 'DB_USERNAME', 'forge' ),
            'password'    => env( 'DB_PASSWORD', '' ),
            'unix_socket' => env( 'DB_SOCKET', '' ),
            'charset'     => 'utf8mb4',
            'collation'   => 'utf8mb4_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
            'modes'       => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],
        ],
    ],
patrique's avatar

After the alter statement ALTER USER '...'@'%' IDENTIFIED WITH mysql_native_password BY '...';

I can connect to mysql 8 (managed digital ocean) command line via mysql 5.x

But with the same credentials laravel still gives an error PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

It must be something with PHP, when i do a small test with a pdo connection i get the same thing Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

I hope anyone can help, and tell me how to use mysql8 with php 7.x

Maldan's avatar

you can try to use this with a fresh empty database in your my.cnf

default-authentication-plugin=mysql_native_password Should work fine. Works even with phpmyadmin

mrborcherds's avatar

This is actually an issue with PHP. You have to be running PHP 7.4 for this to work correctly according to the PHP site. Take a look at this thread https://bugs.php.net/bug.php?id=76243.

Even though you may be running PHP 7.4 you may still have some issues. I have this half fixed so I thought I would post what I have found out about this being a PHP and MySQL 8 issue not a Laravel issue.

1 like
Carmageddon's avatar

@BikashKatwal This worked for me, except I had to use @'%' instead, for it to work when mysql is running inside my docker container, and the application in another container using docker-compose. Obviously not a solution, just a quick workaround for local work while we migrate.. and based on everything said, it sounds like we'll need to upgrade PHP as well to avoid issues needing workarounds for prod env, when we upgrade the SQL server..

Please or to participate in this conversation.