php - 如何让 MySql 8 与 laravel 一起运行?

标签 php mysql laravel ubuntu server

<分区>

我很难让 MySQL 8 正常工作。这是我每次尝试 php artisan migrate 时出现的错误。到目前为止,我只重新安装了 MySQL 一次,因为我不想再为正在发生的事情伤脑筋了。我已经根据其他可能的答案编辑了 database.php ,但这似乎也不起作用。我看到了一个可能的答案,这是因为 MySQL 8 的 root 密码的 sha256 加密,这就是为什么我想回到 MySQL 5.7,我已经查过它可以与 laravel 一起工作。不过,我想让包保持最新,并且只有在我可以让它与 laravel 一起工作时才保留 MySQL 8。

PHP 7.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

最佳答案

由于 PHP 不理解 caching_sha2_password,将用户设置回 mysql_native_password:

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

关于php - 如何让 MySql 8 与 laravel 一起运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52864853/

相关文章:

php - 复选框导调用子邮件提交转到 404

php - 根据写在单元格上的文本显示不同的行颜色

php - Laravel 迁移 : Class "not found"

python - MYSQL: "Access denied for user ' X' @'localhost' (using password: YES)"PYTHON

php - RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException

php - 在mysql中使用WHERE子句显示运行余额但仅显示指定行

mysql - 在 Ruby on Rails 网站中将值(value)从一个网页转移到另一个网页,无需数据库

php - Symfony2 + Doctrine INSERT 查询失败且没有错误

laravel - 为什么在使用Form::open()时CSRF token 为空?

Laravel 5 TokenMismatchException 仅在 iFrame 中