繁体   English   中英

Ruby on rails $ mysql 配置

[英]Ruby on rails $ mysql configuration

我想配置mysql而不是Sqlite3。 我已经配置了database.yml文件:

development:
  adapter: mysql
  database: test
 username:false
 password:neha
 host :localhost
 port:3306

并且还使用gem install mysql安装了 mysql gem

我仍然遇到错误......请帮助我:\\rails\\TestApp1>ruby script/server

http://0.0.0.0:3000上启动 WEBrick Rails 2.3.11 应用程序:/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load': syntax error on line 13, col 0:测试:' (ArgumentError) from C:/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:926:in database_configuration' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:437:in initialize_database' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:141:in process' 来自 C:/Ruby192/lib/ruby/gems/1.9.1/gems /rails-2.3.11/lib/initializer.rb:113:in run' from C:/rails/TestApp1/config/environment.rb:9:in ' from :29:in require' from <internal:lib/rubygems/custom_require>:29:in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in block in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:547:in new_constants_in' 来自 C:/Ruby192/li b/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/commands/server.rb:84:in ' from :29:in require' from <internal:lib/rubygems/custom_require>:29:in require' from script/server:3:in `'我收到这个错误

@d11wtq:
这是我用于 mysql 配置的 yml 文件:

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "本地主机",
:username => "root",
:password => "neha",
:database => "ruby"
)
&我必须放的地方
需要'mysql'

查看您现在发布的日志输出,您似乎没有正确格式化该 .yml 文件。 在 YAML 中使用空格是绝对关键的。 用空格而不是制表符缩进,并确保您的缩进在每个级别内保持一致。 看起来这些行在您的文件中的对齐方式都不同,这导致 syck(YAML 解析器)抛出异常。

编辑 | 您还希望键、分号和值之间的间距也保持一致。 为您的代码布局感到自豪,您会更喜欢编码 ;) 但无论是否自豪... YAML(有意)对空格很挑剔。

让您的 yml 文件正确缩进,您将不再收到语法错误。 还要在你的 Gemfile 中添加 mysql2 兼容版本,这样当你将它部署到任何服务器时,它会自动从 Gemfile 中获取。

您是否将“mysql”添加到 Gemfile 并运行“捆绑安装”?

如果您在 Windows 上工作,我知道我的机器上没有安装 MySQL C 驱动程序。 它与 MySQL 社区服务器的下载不同。 您还必须确保您的PATH具有到 C 驱动程序的路径。 在这里下载驱动程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM