我对symfony有问题。当我尝试运行此命令时:
php app/console doctrine:schema:update --force
我有错误:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
这是我的配置.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
unix_socket: /tmp/mysql.sock
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
和我的参数.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: sil19
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: e7f97888e382ddd2e235dc7da6fc39346b37096c
database_path: null
我不知道问题出在哪里。所以如果有人有任何想法。提前致谢
我必须选中"允许网络访问Mysql"才能使其在MAMP上运行。
我在尝试将 SYMFONY 4 连接到 MAMP Mysql 时遇到了同样的错误:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
就我而言,这是一个错误的Mysql端口,只是将3306更改为8889以修复它
DATABASE_URL=mysql://root:root@127.0.0.1:8889/db_name
在我的 .env 文件中
在完整路径上运行,如下所示:
/Applications/MAMP/bin/php/php5.4.4/bin/php bin/console
在Unix上,MySQL程序特别处理主机名localhost,与其他基于网络的程序相比,其方式可能与您预期的不同。对于与本地主机的连接,MySQL程序尝试使用Unix套接字文件连接到本地服务器。即使提供了 --port 或 -P 选项来指定端口号,也会发生这种情况。要确保客户端与本地服务器建立 TCP/IP 连接,请使用 --host 或 -h 指定主机名值 127.0.0.1,或者指定本地服务器的 IP 地址或名称。您还可以显式指定连接协议,即使对于本地主机,也可以通过使用https://blog.liplex.de/symfony-console-connection-refused-with-mamp/