一切都很好,直到我换了电脑。我正在尝试使用 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= Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
问题是因为在我的旧电脑上我使用的是 MAMP,现在我使用的是 XAMPP,所以在
database.php文件中unix_socket路径是错误的。因此,转到
my.cnf文件并搜索套接字路径,然后确保该套接字路径与unix_socket文件中的database.路径相同