2014-12-03 80 views
0

我剛剛安裝了mysql2創業板Windows 8,並且這樣做的時間非常困難。安裝完成後,我仍然無法運行我的Rails應用程序。無法連接到'127.0.0.1'上的MySQL服務器

系統信息

  • 操作系統:Windows 8的
  • 紅寶石版本:2.0.0p481(2014年5月8日)[I386-的mingw32]

的Gemfile

gem 'mysql2', '0.3.17' 

database.yml的

development: 
    adapter: mysql2 
    encoding: utf8 
    database: db_development 
    pool: 5 
    username: root 
    password: 
    socket: /var/run/mysqld/mysqld.sock 
    host: 127.0.0.1 
    port: 3306 

我得到這個輸出在我的開發日誌

DL is deprecated, please use Fiddle 
=> Booting WEBrick 
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000 
=> Run `rails server -h` for more startup options 
=> Ctrl-C to shutdown server 
[2014-12-03 17:33:49] INFO WEBrick 1.3.1 
[2014-12-03 17:33:49] INFO ruby 2.0.0 (2014-05-08) [i386-mingw32] 
[2014-12-03 17:33:49] INFO WEBrick::HTTPServer#start: pid=53748 port=3000 


Started GET "/" for 127.0.0.1 at 2014-12-03 17:34:07 -0600 

Mysql2::Error (Can't connect to MySQL server on '127.0.0.1' (10061)): 
    mysql2 (0.3.17) lib/mysql2/client.rb:70:in `connect' 
    mysql2 (0.3.17) lib/mysql2/client.rb:70:in `initialize' 
    activerecord (4.0.2) lib/active_record/connection_adapters/mysql2_adapter.rb:1 
8:in `new' 
    activerecord (4.0.2) lib/active_record/connection_adapters/mysql2_adapter.rb:1 
8:in `mysql2_connection' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:440:in `new_connection' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:450:in `checkout_new_connection' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:421:in `acquire_connection' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:356:in `block in checkout' 
    C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:355:in `checkout' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:265:in `block in connection' 
    C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:264:in `connection' 
    activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection 
_pool.rb:546:in `retrieve_connection' 
    activerecord (4.0.2) lib/active_record/connection_handling.rb:79:in `retrieve_ 
connection' 
    activerecord (4.0.2) lib/active_record/connection_handling.rb:53:in `connectio 
n' 
    activerecord (4.0.2) lib/active_record/migration.rb:792:in `current_version' 
    activerecord (4.0.2) lib/active_record/migration.rb:800:in `needs_migration?' 
    activerecord (4.0.2) lib/active_record/migration.rb:379:in `check_pending!' 
    activerecord (4.0.2) lib/active_record/migration.rb:366:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in 
call' 
    activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__768443287_ 
_call__callbacks' 
    activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks' 
    actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `c 
all' 
    actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `ca 
ll' 
    railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tag 
ged' 
    activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged' 
    activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged' 
    railties (4.0.2) lib/rails/rack/logger.rb:20:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.5.2) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.5.2) lib/rack/runtime.rb:17:in `call' 
    activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in ` 
call' 
    rack (1.5.2) lib/rack/lock.rb:17:in `call' 
    actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call' 
    rack (1.5.2) lib/rack/sendfile.rb:112:in `call' 
    railties (4.0.2) lib/rails/engine.rb:511:in `call' 
    railties (4.0.2) lib/rails/application.rb:97:in `call' 
    rack (1.5.2) lib/rack/lock.rb:17:in `call' 
    rack (1.5.2) lib/rack/content_length.rb:14:in `call' 
    rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' 
    C:/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
    C:/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
    C:/Ruby200/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 


    Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispa 
tch/middleware/templates/rescues/_source.erb (1.0ms) 
    Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispa 
tch/middleware/templates/rescues/_trace.erb (3.0ms) 
    Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispa 
tch/middleware/templates/rescues/_request_and_response.erb (3.0ms) 
    Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispa 
tch/middleware/templates/rescues/diagnostics.erb within rescues/layout (101.0ms) 

我跑netstat -a測試我的連接

netstat -a 

Active Connections 

Proto Local Address   Foreign Address   State 
    TCP 0.0.0.0:135   rh-pc:0    LISTENING 
    TCP 0.0.0.0:445   rh-pc:0    LISTENING 
    TCP 0.0.0.0:554   rh-pc:0    LISTENING 
    TCP 0.0.0.0:2869   rh-pc:0    LISTENING 
    TCP 0.0.0.0:5357   rh-pc:0    LISTENING 
    TCP 0.0.0.0:6646   rh-pc:0    LISTENING 
    TCP 0.0.0.0:8732   rh-pc:0    LISTENING 
    TCP 0.0.0.0:10243   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49152   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49153   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49154   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49155   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49158   rh-pc:0    LISTENING 
    TCP 0.0.0.0:49159   rh-pc:0    LISTENING 
    TCP 127.0.0.1:5354   rh-pc:0    LISTENING 
    TCP 127.0.0.1:5354   rh-pc:49156   ESTABLISHED 
    TCP 127.0.0.1:5354   rh-pc:49157   ESTABLISHED 
    TCP 127.0.0.1:27015  rh-pc:0    LISTENING 
    TCP 127.0.0.1:27015  rh-pc:64075   ESTABLISHED 
    TCP 127.0.0.1:49156  rh-pc:5354    ESTABLISHED 
    TCP 127.0.0.1:49157  rh-pc:5354    ESTABLISHED 
    TCP 127.0.0.1:63342  rh-pc:63342   ESTABLISHED 
    TCP 127.0.0.1:64075  rh-pc:27015   ESTABLISHED 
    TCP 192.168.1.114:139  rh-pc:0    LISTENING 
    TCP 192.168.1.114:49565 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49566 93.184.215.200:http CLOSE_WAIT 
    TCP 192.168.1.114:49567 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49568 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49569 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49570 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49571 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49580 a23-33-171-33:https CLOSE_WAIT 
    TCP 192.168.1.114:49583 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49584 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49585 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49586 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49587 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49588 a184-50-238-90:http CLOSE_WAIT 
    TCP 192.168.1.114:49589 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:49590 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:49591 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:49592 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:49593 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:49594 a184-50-238-170:http CLOSE_WAIT 
    TCP 192.168.1.114:51590 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:52160 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:52340 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:53015 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:56954 ord31s21-in-f4:https ESTABLISHED 
    TCP 192.168.1.114:56992 ord31s21-in-f0:https ESTABLISHED 
    TCP 192.168.1.114:56993 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:57369 199.16.156.120:https ESTABLISHED 
    TCP 192.168.1.114:57382 ord08s13-in-f6:https ESTABLISHED 
    TCP 192.168.1.114:57455 64.233.182.95:https ESTABLISHED 
    TCP 192.168.1.114:57488 ord08s06-in-f14:https ESTABLISHED 
    TCP 192.168.1.114:57490 72.21.91.121:https  ESTABLISHED 
    TCP 192.168.1.114:57492 ord08s11-in-f7:http ESTABLISHED 
    TCP 192.168.1.114:57494 a23-67-60-25:http  ESTABLISHED 
    TCP 192.168.1.114:57495 stackoverflow:https ESTABLISHED 
    TCP 192.168.1.114:57502 us:http    TIME_WAIT 
    TCP 192.168.1.114:57507 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57508 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57509 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57510 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57511 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57512 cf-190-93-246-58:http TIME_WAIT 
    TCP 192.168.1.114:57514 72.5.205.11:http  TIME_WAIT 
    TCP 192.168.1.114:57515 ord08s11-in-f7:http TIME_WAIT 
    TCP 192.168.1.114:57516 ord08s11-in-f7:http TIME_WAIT 
    TCP 192.168.1.114:57517 72.21.91.121:https  ESTABLISHED 
    TCP 192.168.1.114:57520 a23-67-60-11:http  TIME_WAIT 
    TCP 192.168.1.114:57521 a23-67-60-11:http  TIME_WAIT 
    TCP 192.168.1.114:57522 103.31.7.32:http  CLOSE_WAIT 
    TCP 192.168.1.114:57523 103.31.7.32:http  TIME_WAIT 
    TCP 192.168.1.114:57524 103.31.7.32:http  TIME_WAIT 
    TCP 192.168.1.114:57525 104.16.12.8:http  TIME_WAIT 
    TCP 192.168.1.114:57526 104.16.12.8:http  TIME_WAIT 

,顯示所有活動連接的列表。我跑了這個,雖然rails s沒有被運行。

這是我lib/ruby/gems/2.0.0/gems/mysql2-0.3.17目錄

examples (Dir) 
ext (Dir) 
lib (Dir) 
spec (Dir) 
support (Dir) 
MIT-LICENSE 
README.md 

這裏是我的`C:/ Program Files文件(86)/ MySQL目錄

MySQL Connector C 6.1 (Dir)        # Only file in this folder 

我花了幾個小時嘗試安裝寶石,之後花了幾個小時解決了這個問題。我無法弄清楚問題所在,但我需要解決這個問題。

非常感謝您的幫助。

+0

我沒有看到任何在端口3306上監聽的東西。你是否成功使用某個客戶端連接到你的mysql實例? mysqladmin也許?另外這一行: ''' socket:/var/run/mysqld/mysqld.sock '''' 看起來不像win8上的工作。而最重要的是:老兄,只是使用Linux進行開發。 – cthulhu 2014-12-04 00:09:43

+0

我不明白爲什麼這不起作用 – Darkmouse 2014-12-04 00:26:49

+0

請回答我的問題:「您是否成功使用某個客戶端連接到您的mysql實例?mysqladmin也許?」 – cthulhu 2014-12-04 00:39:03

回答

1

您的錯誤Can't connect to MySQL server on '127.0.0.1'通常意味着您的MySQL服務未運行。您確定您已將您的應用程序指向您的數據庫服務的正確主機和端口嗎?

+0

我不確定我是否擁有所有正確的文件。在'Program Files(x86)/ MySQL'下,我只有一個文件夾,'MySQL Connector C 6.1' – Darkmouse 2014-12-04 00:00:36

+0

你沒有回答這個問題:你確定你的應用程序指向了你的數據庫的正確的主機和端口服務? – cthulhu 2014-12-04 00:11:07

+0

是的,MySQL在端口3306上運行。我也嘗試過,沒有端口和主機字段 – Darkmouse 2014-12-04 00:26:31

相關問題