Symfony 4 Doctrine无法从控制台运行[2002]没有此类文件或目录 [英] Symfony 4 Doctrine not working from console [2002] No such file or directory

查看:93
本文介绍了Symfony 4 Doctrine无法从控制台运行[2002]没有此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用symfony 4,并且在运行学说控制台命令时会发生此错误:

I´m working with symfony 4 and this error ocurr when runnning doctrine console commands:

In AbstractMySQLDriver.php line 108:

An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory  

我认为这是因为连接有问题,但是当我运行应用程序时,它可以无错误地访问数据库,因此我无法想象连接有什么问题.

I think this is because there´s something wrong with the connection but when I run the application it has access to the database without errors, so I can not imagine what is wrong with the connection.

我能够通过手动创建数据库并使用

I was able to continue working by creating manually the database and using

php bin/console doctrine:schema:create --dump-sql

但这确实是不需要的,因为稍后在需要更新架构时,所有数据都会丢失,因为我需要重新创建架构而不是对其进行更新.

But this is really unwanted because later when the schema needs to be updated all data would be lost because i would need to re-create the schema instead of updating it.

在手动执行SQL之后,该应用程序可以正常运行(easyadmin可以正常运行).

The app works normally after executing manually the SQL (easyadmin works fine).

这是我的配置:

.ENV:

DATABASE_URL=mysql://root:root@127.0.0.1:3306/test

doctrine.yaml:

doctrine.yaml:

parameters:
     env(DATABASE_URL): ''

doctrine:
    dbal:
       driver: 'pdo_mysql'
       server_version: '5.7'
       charset: utf8mb4

我尝试了drop命令只是为了进行测试,并且抛出了这个问题:

I tried the drop command just to test and it throwed this:

In DropDatabaseDoctrineCommand.php line 93:


Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.  

所以我将dbname添加到doctrine.yaml中,但没有用. 我还尝试过删除缓存,创建一个新项目,使用远程mysql和使用sqlite,但是在两种情况下,错误都是相同的!

So I add dbname to doctrine.yaml and didn´t worked. I also tried removing the cache, creating a new project, using a remote mysql, and using sqlite but the errors are the same in both cases !!

预先感谢您的帮助!

推荐答案

请从DB_HOST=localhost更改为DB_HOST=127.0.0.1

DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}

这篇关于Symfony 4 Doctrine无法从控制台运行[2002]没有此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆