我从名为laravel
的Laravel5.4数据库中删除了migrations
表。当我运行php 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)
我删除并重新创建了数据库。我还运行了composer update
。不走运。我可以在phpMyAdmin中运行该命令并手动创建表。
这个问题有时也会出现类似的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')
发布于 2017-09-25 22:23:47
如果在.env
文件中使用localhost
作为DATABASE_HOST
,请将其更改为127.0.0.1
,然后运行php artisan config:clear
,然后再次尝试php artisan migrate:install
。
发布于 2019-04-04 01:50:30
以下是我对.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
发布于 2020-06-02 01:14:27
我通过在.env
文件中设置环境变量修复了此问题:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
实际上我刚从DB_HOST=127.0.0.1
改成了DB_HOST=mysql
。
https://stackoverflow.com/questions/46407490
复制相似问题