php - 数据库迁移在 Laravel 7 中不起作用
问题描述
我在所有 Laravel 项目中都遇到了这种类型的异常。
Illuminate\Database\QueryException
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = orchid and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+34 vendor frames
35 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
我试图通过.env
设置解决它。
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=orchid
DB_USERNAME=root
DB_PASSWORD=password
但它不起作用。
之后我composer require doctrine/dbal
在我的 Laravel 项目中安装了包,但它不工作。我无法理解如何解决它。
解决方案
我试试这个解决方案。它帮助到我。
- 以root身份登录mysql
- 运行这个 sql 命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';