Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails “当我跑的时候”;轨道s";在命令提示符下,我收到一个MySQL2::Error_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails “当我跑的时候”;轨道s";在命令提示符下,我收到一个MySQL2::Error

Ruby on rails “当我跑的时候”;轨道s";在命令提示符下,我收到一个MySQL2::Error,ruby-on-rails,ruby,Ruby On Rails,Ruby,我对使用RubyonRails运行站点非常陌生。一点背景故事: 所以我在做一个项目,我得到了网站的代码。我正在运行Windows,所以我知道它不是RoR的最佳操作系统,但切换到其他操作系统是我最后的选择 我从RailsInstaller.org获得了RailsInstaller,并运行了它。一切安装顺利 我从我的站点目录运行了bundle安装,并遇到了gem“therubyracer”的问题。做了一系列的搜索,发现Windows不需要宝石。我想。因此,我在gem文件中注释掉了gem,并再次运行了

我对使用RubyonRails运行站点非常陌生。一点背景故事:

所以我在做一个项目,我得到了网站的代码。我正在运行Windows,所以我知道它不是RoR的最佳操作系统,但切换到其他操作系统是我最后的选择

我从RailsInstaller.org获得了RailsInstaller,并运行了它。一切安装顺利

我从我的站点目录运行了
bundle安装
,并遇到了gem“therubyracer”的问题。做了一系列的搜索,发现Windows不需要宝石。我想。因此,我在gem文件中注释掉了gem,并再次运行了
bundle安装。一切都很好

我试图通过命令提示符运行
rails s
,但收到一个错误:

The program can't start because LIBMYSQL.dll is missing from your computer.
所以我做了一些研究,发现我必须将文件复制到RailsInstaller目录下的Ruby/bin文件夹中。错误消失了

最后,我再次运行了
rails s
,服务器被置于localhost之下。我想。无论如何,我去了
localhost:3000
,收到了一个MySQL2::错误,
无法连接到“localhost”(10061)
上的MySQL服务器。当我点击
Full Trace
时,我得到了代码:

development/ruby/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect'
development/ruby/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `initialize'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:303:in `new_connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:313:in `checkout_new_connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:237:in `block (2 levels) in checkout'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:232:in `loop'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:232:in `block in checkout'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/query_cache.rb:67:in `rescue in call'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/query_cache.rb:61:in `call'
development/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
development/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `_run__132547094__call__984979790__callbacks'
development/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
development/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
development/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:65:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
development/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:26:in `call_app'
development/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb:16:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/request_id.rb:22:in `call'
development/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
development/ruby/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
development/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
development/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
development/ruby/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/static.rb:62:in `call'
development/ruby/1.9.1/gems/railties-3.2.3/lib/rails/engine.rb:479:in `call'
development/ruby/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:220:in `call'
development/ruby/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
development/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/log_tailer.rb:14:in `call'
development/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
我仔细研究了一下,发现

当我在命令提示符下尝试ping localhost时,我得到了上面的注释:

Reply from ::1: time<1ms
Reply from::1:time您可以使用检查服务器状态

DBMS的配置在Rails项目的
db/database.yml
文件中设置


我建议您阅读一些关于Rails的知识,以及关于数据库存储的一般知识。您可以从使用SQLite的开始。MySQL和SQLite是Rails通常用于存储需要长期保存的信息的不同版本。

您的本地计算机上是否运行MySQL?另外,
database.yml
(包括数据库、用户名和密码)中的配置是否与您的MySQL实例匹配?您是如何创建项目的?你是刚使用脚手架还是从一本书/教程中复制了部分代码?哇,你真的是从头开始。主机是提供服务的计算机,例如web服务器。在这种情况下,主机是您的计算机。Web通信使用IP地址(通常有example.com之类的域名)完成,而一个特殊的IP地址127.0.0.1是计算机的IP地址,并命名为
localhost
。正如@PinnyM所建议的,很可能需要运行数据库服务器MySQL。如果你刚开始,Rails还使用一个简单的本地数据库,称为SqLITE,你可能需要考虑。@ PNYNMM我如何判断我是否有MySQL运行?我确实下载了安装程序,并安装了它。这是否意味着它正在运行?在哪里可以找到
数据库.yml
@stsd我从github获得了项目代码,并使用github应用程序将其下载到我的计算机上。MySQL和SQLLite到底是什么?它有什么作用@Tharrison感谢您的链接。=]所以,我重新安装了MySQL。当我检查工作台时,它现在在左列显示了本地实例MySQL55。用户是
root
,主机是
localhost:3306
。我应该在database.yml中输入什么?更具体地说,“数据库:”字段中应该包含什么?我将用户设置为root,并将密码设置为我定义的密码。您首先需要为rails应用程序创建一个数据库。您可以使用工作台创建一个(工作台称之为“模式”)。将其命名为“yourapp_development”,其中“yourapp”是您将记住的与您的应用程序相关联的内容。在这期间,创建另一个名为“yourapp\u测试”的数据库。在database.yml中的开发部分set
database:yourapp\u development
和测试部分set
database:yourapp\u test
。好的,我已经完成了,并且我已经将
database.yml
中的所有字段设置为正确的设置。但是,当我从命令提示符运行
rails s
并尝试连接到
localhost:3000
时,仍然收到相同的错误。我还可能缺少什么/做错了什么?在database.yml文件中,尝试将
host:localhost
更改为
host:127.0.0.1
没有用于
host
的字段。我应该在开发部分创建它吗?