首页 > 解决方案 > 如何在本地 laravel 8sai 安装中使用 mysql

问题描述

我正在学习 Laravel 8,我是初学者。我尝试通过 Sail 安装它以利用 Docker。终端:

curl -s "https://laravel.build/learnlaravel" | bash
cd learnlaravel
./vendor/bin/sail up

现在去 localhost 我看到 Laravel 欢迎页面,一切正常。

如果我做:

php artisan migrate

我收到此错误:

xlf @ MBP16-XLF learnlaravel% php artisan migrate

   Illuminate \ Database \ QueryException

  SQLSTATE [HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = learnlaravel and table_name = migrations and table_type = 'BASE TABLE')

  at vendor / laravel / framework / src / Illuminate / Database / Connection.php: 678
    674▕ // If an exception occurs when attempting to run a query, we'll format the error
    675▕ // message to include the bindings with SQL, which will make this exception a
    676▕ // lot more helpful to the developer instead of just the database's errors.
    677▕ catch (Exception $ e) {
  ➜ 678▕ throw new QueryException (
    679▕ $ query, $ this-> prepareBindings ($ bindings), $ e
    680▕);
    681▕}
    682▕

有人可以用简单的话向我解释我做错了什么或我应该做什么吗?mySQL 数据库是否已经在 Docker 上?如何登录以使用 .env 文件的凭据创建和配置它?谢谢你的理解和支持 :)

标签: mysqllaraveldocker

解决方案


尝试

./vendor/bin/sail artisan migrate

代替

php artisan migrate

文档:https ://laravel.com/docs/8.x/artisan#laravel-sail

此外,您可以安装任何数据库管理器并使用此凭据连接到您的数据库以查看和配置它。


推荐阅读