SQLSTATE [HY000] [2002]拒绝连接 - MAMP& Symfony 2

时间:2015-01-19 13:09:03

标签: php symfony pdo doctrine-orm

我遇到了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

我不知道问题出在哪里。所以,如果有人有任何想法。提前致谢

4 个答案:

答案 0 :(得分:12)

我要检查“允许网络访问Mysql”以使其在MAMP上运行。

答案 1 :(得分:1)

尝试将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文件中

答案 2 :(得分:0)

以完整路径运行,如下所示:

/Applications/MAMP/bin/php/php5.4.4/bin/php bin/console

答案 3 :(得分:0)

在Unix上,MySQL程序特别对待主机名localhost,与其他基于网络的程序相比,它可能与您期望的方式不同。为了连接到localhost,MySQL程序尝试使用Unix套接字文件连接到本地服务器。即使给--port或-P选项指定了端口号,也会发生这种情况。为确保客户端与本地服务器建立TCP / IP连接,请使用--host或-h指定主机名值127.0.0.1或本地服务器的IP地址或名称。您还可以使用以下命令显式指定连接协议,即使是本地主机也可以。 https://blog.liplex.de/symfony-console-connection-refused-with-mamp/