运行迁移时“没有这样的文件或目录”或“没有这样的主机是已知的”

2022-08-30 13:00:16

我从名为 的Laravel 5.4数据库中删除了该表。当我运行时,我得到这个错误:migrationslaravelphp artisan migrate:install

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory
(SQL: select * from information_schema.tables where table_schema = laravel
    and table_name = migrations)

我删除并重新创建了数据库。我也跑了.没有运气。我可以在phpMyAdmin中运行该命令并手动创建表。composer update

此问题有时也会表现为类似的 2002 错误:

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
(SQL: select * from information_schema.tables where table_schema = laravel
    and table_name = migrations and table_type = 'BASE TABLE')
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
(SQL: select * from information_schema.tables where table_schema = laravel
    and table_name = migrations and table_type = 'BASE TABLE')

答案 1

如果在文件中用作,请将其更改为 ,然后运行,现在重试。localhostDATABASE_HOST.env127.0.0.1php artisan config:clearphp artisan migrate:install


答案 2

以下是我对文件的建议:.env

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306

然后在添加文件夹位置:Database.php

'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),

最后,尝试:

php artisan config:clear
php artisan migrate:install

推荐