Laravel:没有这样的文件或目录(SQL:创建表`migrations`)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46407490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:50:13  来源:igfitidea点击:

Laravel: No such file or directory (SQL: create table `migrations`)

laravellaravel-5.4artisan

提问by Jay Bienvenu

I deleted the migrationstable from a Laravel 5.4 database named laravel. When I run php artisan migrate:install, I get this error:

migrations从名为的 Laravel 5.4 数据库中删除了该表laravel。当我运行时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)

I deleted and recreated the database. I also ran composer update. No luck. I can run the command in phpMyAdmin and create the table manually.

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

回答by Camilo

If you are using localhostas your database host, change it to 127.0.0.1, then run php artisan config:clearand now try php artisan migrate:installagain.

如果您localhost用作数据库主机,请将其更改为127.0.0.1,然后运行,然后php artisan config:clear再试php artisan migrate:install一次。

回答by kaleazy

Here's what I recommend for .envfile:

这是我推荐的.env文件:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306

Then in Database.phpadd folder location:

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

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

Finally, try:

最后,尝试:

php artisan config:clear
php artisan migrate:install

回答by felmez

I am using MAMP on macOS and after editing localhost to 127.0.0.1 and port to 8888 this problem fixed by adding the following

我在 macOS 上使用 MAMP,在将 localhost 编辑为 127.0.0.1 并将端口编辑为 8888 后,通过添加以下内容解决了此问题

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

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

to config/database.php file.

到 config/database.php 文件。

回答by William M

In some cases this may happen because mysql server is not running. It happened to me using Laravel 5.7 and restarting mysql server solved it. For ubuntu check the status of mysql server service mysql status. You can restart mysql server using command service mysql restart

在某些情况下,这可能是因为 mysql 服务器没有运行。它发生在我使用 Laravel 5.7 并重新启动 mysql 服务器解决它。对于 ubuntu 检查 mysql 服务器的状态service mysql status。您可以使用命令重新启动 mysql 服务器service mysql restart

回答by Jeroen

Maybe try the following commands

也许尝试以下命令

Rollback:

回滚:

php artisan migrate:rollback

Or a reset using:

或者使用以下方法重置:

php artisan migrate:reset

or do a refresh:

或刷新:

php artisan migrate:refresh

回答by Jay Bienvenu

I deleted the folder and recreated the code base, making sure to point my environment to the correct database server. This time it worked. I don't know exactly what had gone missing to cause the original error.

我删除了该文件夹并重新创建了代码库,确保将我的环境指向正确的数据库服务器。这次成功了。我不知道究竟是什么导致了原始错误。

回答by user10291311

I am working with Mamp, so my Unix Socket is given:

我正在使用 Mamp,因此给出了我的 Unix 套接字:

localhost:/Applications/MAMP/tmp/mysql/mysql.sock

By connecting laravel with the database, I also get the error on the top. My solution was to take the socket without "localhost:" (It is a local installation)

通过将laravel与数据库连接,我也得到了顶部的错误。我的解决方案是在没有“localhost:”的情况下使用套接字(这是本地安装)

So try the Socket: /Applications/MAMP/tmp/mysql/mysql.sock

所以试试 Socket:/Applications/MAMP/tmp/mysql/mysql.sock

回答by James Cushing

If you are using MAMP Pro (not always necessary for the free version of MAMP) then the best thing to do is add this to your .envfile:

如果您使用的是 MAMP Pro(MAMP 的免费版本并不总是必需的),那么最好的做法是将其添加到您的.env文件中:

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

This assumes your MAMP installation is at /Applications/MAMPof course (the default).

/Applications/MAMP当然假设您的 MAMP 安装是(默认)。

Credit: A comment in this question by @Uncoke

信用:@Uncoke 在这个问题中的评论

回答by steve7n

On Mac and MAMP, removing DB_HOSTfrom .envalso works.

在 Mac 和 MAMP 上,删除DB_HOSTfrom.env也有效。

Acknowledgement: Comment by Leap Hawk

致谢:Leap Hawk 的评论