我已经阅读了与这个问题相关的每一篇文章,但似乎没有什么对我有用
我想用以下命令创建一个数据库:
$php-bin/console原则:数据库:创建
错误为:
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] Connection refused
doctrine:database:create [--shard SHARD] [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
到目前为止我尝试过的:
- 我已经更新了服务器版本
- 我将127.0.0.1更改为localhost
- 我在phpmyadmin中创建了一个新用户
My.env文件如下所示:
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://root:123@127.0.0.1:3306/myproject?serverVersion=10.4.11
###< doctrine/doctrine-bundle ###
我的学说.yaml文件如下所示:
doctrine:
dbal:
driver: pdo_mysql
server_version: '10.4.11'
url: '%env(resolve:DATABASE_URL)%'
我感谢任何帮助!
这就是标准doctrine.yaml(SF5.0!,Doctrine2.0(的样子
//YOUR_NAMESPACE\config\packages\doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
server_version: '10.4'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'YOUR_NAMESPACEEntity'
alias: YOUR_NAMESPACE
和.env.local
DATABASE_URL=mysql://root:123@127.0.0.1:3306/myproject2
您的composer.json应该包含在require段中
"doctrine/doctrine-bundle": "^2.0",
"doctrine/doctrine-migrations-bundle": "2.1.*",
"doctrine/orm": "2.7.*",
并且在您的docrine_migrations.yaml 中
//YOUR_NAMEMESPACE\config\packages\doctrine_migrations.yaml
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from AppMigrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations