title: How to get MySql 8 to run with laravel?
body: <p>I'm having difficulty getting MySQL 8 to work. This is the error that appears everytime I attempt a <code>php artisan migrate</code>. I've reinstalled MySQL only once so far because I didn't want to hurt my head anymore on what was going on. I've edited the <code>database.php</code> from other possible answers, but that also doesn't seem to work. I saw a possible answer that it's because of MySQL 8's sha256 encryption of the root password, which is why I want to go back to MySQL 5.7 which I've looked up works with laravel just fine. Though, I want to keep the packages up to date and keep MySQL 8 only if i can get it to work with laravel.</p>
  
  <p>PHP 7.2</p>
  
  <p>How do I get MySQL 8 to work with Laravel?</p>
  
  <pre><code> 'mysql' =&gt; [
              'driver' =&gt; 'mysql',
              'host' =&gt; env('DB_HOST', '127.0.0.1'),
              'port' =&gt; env('DB_PORT', '3306'),
              'database' =&gt; env('DB_DATABASE', 'forge'),
              'username' =&gt; env('DB_USERNAME', 'forge'),
              'password' =&gt; env('DB_PASSWORD', ''),
              'unix_socket' =&gt; env('DB_SOCKET', ''),
              'charset' =&gt; 'utf8',
              'collation' =&gt; 'utf8_unicode_ci',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,
              'strict' =&gt; true,
              'engine' =&gt; null,
              'version' =&gt; 8,
              'modes' =&gt; [
                  'ONLY_FULL_GROUP_BY',
                  'STRICT_TRANS_TABLES',
                  'NO_ZERO_IN_DATE',
                  'NO_ZERO_DATE',
                  'ERROR_FOR_DIVISION_BY_ZERO',
                  'NO_ENGINE_SUBSTITUTION',
              ],
          ],
  </code></pre>
  
  <p>``</p>
  
  <pre><code>Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = laravel_tut and table_name = migrations)
  
    at /Users/home/Projects/laravel_tut/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) {
    &gt; 664|             throw new QueryException(
      665|                 $query, $this-&gt;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/home/Projects/laravel_tut/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
  
    2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel_tut", "root", "fdgkadgaf9g7ayaig9fgy9ad8fgu9adfg9adg", [])
        /Users/home/Projects/laravel_tut/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
  </code></pre>
  
  <p><strong>UPDATE ANOTHER FIX I DID TO FIX THIS:</strong>
  With a fresh install of MySQL, i selected NO for encrypting passwords in the set up ( using legacy encryption, not the SHA encryption ) and it started to work with Laravel without any problems - Just use a long and strong password.
  reference of the installation step:
  <a href="https://www.percona.com/blog/wp-content/uploads/2018/05/Installing-MySQL-8.0-on-Ubuntu-2.png" rel="noreferrer">https://www.percona.com/blog/wp-content/uploads/2018/05/Installing-MySQL-8.0-on-Ubuntu-2.png</a></p>