我的任务是在我的工作站上设置laravel,这对我来说已经非常复杂了。
在设置mysql时,出现以下错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = techpocket and table_name = migrations)
at /Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
/Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
2 PDO::__construct("mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=techpocket", "root", "", [])
/Users/George/Sites/TechPocketnews/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
Please use the argument -v to see more details.
当我尝试运行命令时:
php artisan migrate
下面是我在app/config/database.php文件中的mysql配置:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
下面是我在.env文件中的mysql配置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=techpocket
DB_USERNAME=root
DB_PASSWORD=
我是拉威尔的新手,对我好点:)
谢谢你的帮助。
旁注:我正在运行php7.1.7、mysql 8.11和laravel5.4
2条答案
按热度按时间kgsdhlau1#
自从我使用mamp后就有同样的问题。我使用的是laravel5.7,因此mydatabase.php在mysql指令下有一行:
'unix\u socket'=>env('db\u socket',''),
解决方案是添加环境文件中缺少的db\u socket选项:
db\u socket=/applications/mamp/tmp/mysql/mysql.sock
vs91vp4v2#
添加到app/providers/appserviceproviders.php:
看看这个。希望有用。
注意:你仍然有错误
在.env文件中。