SQLSTATE[HY000] [2002] 连接被拒绝 - MAMP 和 Symfony 2
SQLSTATE[HY000] [2002] Connection refused - MAMP & Symfony 2
我对 symfony 有疑问。
当我尝试 运行 这个命令时:
php app/console doctrine:schema:update --force
我有错误:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
这是我的 config.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 }
还有我的parameters.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
不知道问题出在哪里。所以如果有人有任何想法。提前致谢
我必须检查 "Allow network access to Mysql" 才能使其在 MAMP 上运行。
运行 在完整路径处,像这样:
/Applications/MAMP/bin/php/php5.4.4/bin/php bin/console
我在尝试将 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 文件中
在 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/
我对 symfony 有疑问。 当我尝试 运行 这个命令时:
php app/console doctrine:schema:update --force
我有错误:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
这是我的 config.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 }
还有我的parameters.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
不知道问题出在哪里。所以如果有人有任何想法。提前致谢
我必须检查 "Allow network access to Mysql" 才能使其在 MAMP 上运行。
运行 在完整路径处,像这样:
/Applications/MAMP/bin/php/php5.4.4/bin/php bin/console
我在尝试将 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 文件中
在 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/