Laravel 6.0 迁移 - SQLSTATE[HY000] [2002] 没有那个文件或目录
Laravel 6.0 migration - SQLSTATE[HY000] [2002] No such file or directory
我正在尝试使用 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
我检查套接字是否存在,我还创建了一个link到/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
我终于找到了解决方案,macOS 中最新版本的 xampp 可以与虚拟机一起使用,所以当我 运行 迁移时,它是在我的计算机上获取数据库,而不是在本地机器。
在没有虚拟机的情况下下载最新版本!
这里我有两个解决方案
更改您的 .env 文件
DB_HOST=127.0.0.1
到
DB_HOST=localhost
然后 运行 按照命令清除配置文件
php artisan config:clear
解决此问题的第二种方法是在 .env 文件中添加以下行
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
FOR Mac OS,尝试在您的 .env
中添加以下行
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
我正在尝试使用 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
我检查套接字是否存在,我还创建了一个link到/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
我终于找到了解决方案,macOS 中最新版本的 xampp 可以与虚拟机一起使用,所以当我 运行 迁移时,它是在我的计算机上获取数据库,而不是在本地机器。 在没有虚拟机的情况下下载最新版本!
这里我有两个解决方案
更改您的 .env 文件
DB_HOST=127.0.0.1
到
DB_HOST=localhost
然后 运行 按照命令清除配置文件 php artisan config:clear
解决此问题的第二种方法是在 .env 文件中添加以下行
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
FOR Mac OS,尝试在您的 .env
中添加以下行DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock