php artisan migrate not working Laravel 8

12 浏览
0 Comments

php artisan migrate not working Laravel 8

一切都很好,直到我更换了电脑。我正在尝试使用php artisan migrate迁移我的数据库,但是我遇到了这个错误

  SQLSTATE[HY000] [2002] 没有该文件或目录 (SQL: select * from information_schema.tables where table_schema = grain and table_name = migrations and table_type = 'BASE TABLE')
  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // 如果在运行查询时发生异常,我们将格式化错误消息以包含带有 SQL 的绑定,这将使开发人员获得更多有用的信息,而不仅仅是数据库的错误。
    709▕         // 捕捉异常
    710▕         // 将异常抛出为查询异常
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }
      +33 vendor frames 
  34  artisan:35
      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=grain
    DB_USERNAME=root
    DB_PASSWORD=

0
0 Comments

问题是因为我在旧电脑上使用MAMP,现在使用XAMPP,所以在database.php文件中unix_socket路径是错误的。

所以打开my.cnf文件,搜索socket路径,确保socket路径与database.php文件中的unix_socket路径相同。

0