如何让mysql 8与laravel一起运行?

enxuqcxy  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(399)

这个问题在这里已经有答案了

php with mysql 8.0+错误:服务器请求的身份验证方法客户端未知[重复](8个答案)
4个月前关门了。
我很难让mysql 8正常工作。这是每次我尝试 php artisan migrate . 到目前为止,我只重新安装了一次mysql,因为我不想再为发生的事情伤脑筋。我已经编辑了 database.php 从其他可能的答案来看,但这似乎也不管用。我看到了一个可能的答案,那是因为mysql 8的sha256根密码加密,这就是为什么我想回到mysql 5.7,我查过它与laravel一起工作很好。不过,我想让包保持最新,只有在我能让MySQL8与laravel一起工作的情况下,我才能保持MySQL8。
PHP7.2
如何让mysql 8与laravel一起工作?

'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' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'version' => 8,
            'modes' => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],
        ],

``

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) {
  > 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/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

更新我做的另一个修复程序来修复这个问题:通过新安装的mysql,我在设置中为加密密码选择了no(使用传统加密,而不是sha加密),它开始与laravel一起工作,没有任何问题—只需使用长而强的密码。安装步骤参考:https://www.percona.com/blog/wp-content/uploads/2018/05/installing-mysql-8.0-on-ubuntu-2.png

jecbmhm3

jecbmhm31#

因为php不懂 caching_sha2_password ,将用户设置回 mysql_native_password :

ALTER USER 'forge'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'new_password'
flseospp

flseospp2#

在运行7.1.16之前的php版本或7.2.4之前的php 7.2时,请将mysql 8服务器的默认密码插件设置为mysql\ U native\ U password,否则即使未使用caching\ U sha2\ U password,您也会看到类似于客户端未知的服务器请求的身份验证方法的错误[caching\ U sha2\ U password]。
https://www.php.net/manual/en/mysqli.requirements.php
这也有助于:
https://php.watch/articles/php-7.4-mysql-8-server-gone-away-fix

相关问题