2016-07-01 43 views
2

我想跟着一个电子商务教程,我必须创建与数据库的连接。我在Windows 7上使用xampp v3.2。如何解决这个SQLSTATE [HY000] [2002]无法建立连接,因为目标机器主动拒绝它

所以我用这个:PHP斌/控制台产生:学说:实体 这给了我这个错误:

SQLSTATE [HY000]可以作出不连接[2002]因为目标 机器积极拒绝它

我关闭xampp,我仍然有同样的错误。所以我明白它来自配置;不知何故,我的外壳不能从xampp与我的sql服务器进行通信。

这里是我的parameters.yml:

# This file is auto-generated during the composer install 
parameters: 
    database_host: localhost 
    database_port: 3306 
    database_name: market 
    database_user: sebastian 
    database_password: 
    mailer_transport: smtp 
    mailer_host: localhost 
    mailer_user: null 
    mailer_password: null 
    secret: 

,在这里我config.yml

imports: 
    - { resource: parameters.yml } 
    - { resource: security.yml } 
    - { resource: services.yml } 
    - { resource: "@EcommerceBundle/Resources/config/services.yml" } 

# Put parameters here that don't need to change on each machine where the app is deployed 
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration 
parameters: 
    locale: en 

framework: 
    #esi:    ~ 
    #translator:  { fallbacks: ["%locale%"] } 
    secret:   "%secret%" 
    router: 
     resource: "%kernel.root_dir%/config/routing.yml" 
     strict_requirements: ~ 
    form:   ~ 
    csrf_protection: ~ 
    validation:  { enable_annotations: true } 
    #serializer:  { enable_annotations: true } 
    templating: 
     engines: ['twig'] 
    default_locale: "%locale%" 
    trusted_hosts: ~ 
    trusted_proxies: ~ 
    session: 
     # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id 
     handler_id: session.handler.native_file 
     save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" 
    fragments:  ~ 
    http_method_override: true 
    assets: ~ 

# Twig Configuration 
twig: 
    debug:   "%kernel.debug%" 
    strict_variables: "%kernel.debug%" 

# Doctrine Configuration 
doctrine: 
    dbal: 
     driver: pdo_mysql 
     host:  "%database_host%" 
     port:  "%database_port%" 
     dbname: "%database_name%" 
     user:  "%database_user%" 
     password: "%database_password%" 
     charset: UTF8 
     # 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%" 
     naming_strategy: doctrine.orm.naming_strategy.underscore 
     auto_mapping: true 

# Swiftmailer Configuration 
swiftmailer: 
    transport: "%mailer_transport%" 
    host:  "%mailer_host%" 
    username: "%mailer_user%" 
    password: "%mailer_password%" 
    spool:  { type: memory } 

我检查扩展php_pdo_mysql.dl并启用。

我验证了数据库名称,用户名和密码。

这里是一个netstat的: netstat

+0

据'parameters.yml'没有数据库所需的密码。它是由您删除还是没有确实需要密码? – geoB

+0

我删除它,秘密一样! –

+0

在创建安装symfony时,我给了database_port:8080,然后在将端口更改为database_port:3306后,我遇到了这个问题,它会解决我的问题。 –

回答

0

确保你的MySQL服务器正在运行,并且它使用该端口(在XAMPP \ mysql的\ BIN \ my.ini文件)。确保您也可以手动连接这些凭据。

此外,你在你的parameters.yml中指定数据库驱动程序?通常情况下,你应该有这样的事情:

database_driver: pdo_mysql 

最后,确保你没有包含在config_dev.yml不同parameters.yml文件,因为Symfony的命令,默认情况下,使用开发环境。

0

谢谢你的回答。 我在my.ini 3306端口,所以它是好的。我已经安装了symfony2.8,它正在工作,所以没有证书问题。我也试着用pdo_mysql添加这行,但是错误信息是一个pdo_exception,这意味着pdo也适用。 我也检查config.dev,但我真的不知道里面可能会出现什么问题。所以,我告诉你是什么样子:

imports: 
    - { resource: config.yml } 

framework: 
    router: 
     resource: "%kernel.root_dir%/config/routing_dev.yml" 
     strict_requirements: true 
    profiler: { only_exceptions: false } 

web_profiler: 
    toolbar: true 
    intercept_redirects: false 

monolog: 
    handlers: 
     main: 
      type: stream 
      path: "%kernel.logs_dir%/%kernel.environment%.log" 
      level: debug 
      channels: [!event] 
     console: 
      type: console 
      channels: [!event, !doctrine] 
     # uncomment to get logging in your browser 
     # you may have to allow bigger header sizes in your Web server configuration 
     #firephp: 
     # type: firephp 
     # level: info 
     #chromephp: 
     # type: chromephp 
     # level: info 

#swiftmailer: 
# delivery_address: [email protected] 

感谢您的帮助

相关问题