Laravel 8:解決 php artisan migrate 不起作用的問題
P粉885035114
P粉885035114 2024-03-30 17:41:04
0
1
336

一切都很好,直到我換了電腦。我正在嘗試使用 php artisan migrate 遷移我的資料庫,但出現此錯誤

SQLSTATE[HY000] [2002] No such file or directory (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▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    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=

P粉885035114
P粉885035114

全部回覆(1)
P粉794851975

問題是因為在我的舊電腦上我使用的是 MAMP,現在我使用的是 XAMPP,所以在 database.php 檔案中 unix_socket 路徑是錯誤的。

因此,請前往my.cnf 檔案並蒐索套接字路徑,然後確保該套接字路徑與unix_socket 檔案中的database.路徑相同

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!