2016-07-01 89 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] 

感謝您的幫助

相關問題