0

我正在尝试使用 laravel 创建迁移,但出现此错误:

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

  at /Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
    661|         // If an exception occurs when attempting to run a query, we'll format the error
    662|         // message to include the bindings with SQL, which will make this exception a
    663|         // lot more helpful to the developer instead of just the database's errors.
    664|         catch (Exception $e) {
  > 665|             throw new QueryException(
    666|                 $query, $this->prepareBindings($bindings), $e
    667|             );
    668|         }
    669| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
      /Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:unix_socket=/var/mysql/mysql.sock;dbname=tutories", "root", "", [])
      /Users/ivanortega/.bitnami/stackman/machines/xampp/volumes/root/htdocs/codi/UVIC/Tutories/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

我试图更改主机名和套接字。没有任何效果

这是我的 .env 配置文件:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tutories
DB_USERNAME=root
DB_PASSWORD=
DB_SOCKET=/var/mysql/mysql.sock

我检查了套接字是否存在,并且我还创建了一个指向 /tmp/mysql.sock 的链接。我更改了 php.ini 文件:

pdo_mysql.default_socket=/var/mysql/mysql.sock

程序版本:

XAMPP: 7.3.9
PHP: 7.3.6
MariaDB: 10.0.34
MAC:MacOS Mojave v10.14.6
4

2 回答 2

1

最后我找到了解决方案,macOS 中最新版本的 xampp 可与虚拟机一起使用,因此当我运行迁移时,它在我的计算机上获取数据库,而不是在本地机器上。在没有虚拟机的情况下下载最新版本有效!

于 2019-11-22T09:29:18.370 回答
0

在这里我有两个解决方案

  1. 改变你的 .env 文件

    DB_HOST=127.0.0.1

    DB_HOST=localhost

    然后运行以下命令清除配置文件 php artisan config:clear

  2. 解决此问题的第二种方法是在 .env 文件中添加以下行

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

于 2021-10-08T08:20:13.343 回答