我安装了 MySQL 8 和 Laravel 5.6.18;当我尝试使用以下命令运行迁移时:php artisan migrate
我的迁移示例是:
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('nombre')->unique()->index();
$table->string('descripcion', 500);
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->timestamps();
});
评论:我的迁移顺序是正确的,就是先有迁移用户,再有分类,再有帖子
但是我收到以下错误
PDOException::("PDO::__construct(): 服务器请求客户端未知的身份验证方法 [caching_sha2_password]")。
应该注意的是,使用 5.7 版的 Mysql 我执行迁移没有任何问题
问题是您更改了 MySQL 8 中的默认身份验证,这导致了此错误。
为了解决这个问题,建议执行以下几行,或者只执行其中的第一部分,视情况而定,显然您必须将
user
y替换password
为适当的值:这对我有用:
首先我创建了一个新用户:
然后我配置了config/database.php文件(https://github.com/laravel/framework/pull/23948):
最后我配置了.env:
聪明的!!!
对于 MySql 8,我通过在安装过程中更改配置中的身份验证方法来解决它。住宿方式如下:
对我来说 sql 命令有效
并阅读评论