简体   繁体   English

Rails无法使用mysql生成模型

[英]Rails cannot generate model using mysql

Windows XP with installed MYSQL as a development machine, ruby 1.9.2p290 (2011-07-09) [i386-mingw32], Rails 3.1.0 gem install mysql2 -- '--with-mysql-lib="c:\\Program Files\\MySQL\\MySQL S erver 5.5\\lib" --with-mysql-include="c:\\Program Files\\MySQL\\MySQL Server 5.5\\inc lude"' (successfully installed gem mysql2) rails new talk -d mysql (successfully created a new rails app called talk) 安装了MYSQL作为开发机器的Windows XP,ruby 1.9.2p290(2011-07-09)[i386-mingw32],Rails 3.1.0 gem install mysql2-'--with-mysql-lib =“ c:\\ Program Files \\ MySQL \\ MySQL Server 5.5 \\ lib“ --with-mysql-include =” c:\\ Program Files \\ MySQL \\ MySQL Server 5.5 \\ inc lude“'(成功安装gem mysql2)引起了新话题-d mysql(成功创建了一个名为talk的新Rails应用)


PROBLEM NOW STARTS: 现在开始的问题:


C:\\Sites\\RP\\talk>rails generate User ERROR MESSAGE: ruby.exe-Unable to Locate Component This application has failed to start because libmysql.dll was not found. C:\\ Sites \\ RP \\ talk> rails生成用户错误消息:ruby.exe-无法找到组件此应用程序无法启动,因为未找到libmysql.dll。 Re-installing the application may fix this problem. 重新安装该应用程序可能会解决此问题。 COMMAND LINE ERROR MESSAGE: C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb :9:in require': 126: The specified module could not be found. - C:/RailsInsta ller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2/mysql2.so (Load Error) from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/ lib/mysql2.rb:9:in 命令行错误消息:C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in require': 126: The specified module could not be found. - C:/RailsInsta ller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2/mysql2.so (Load Error) from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/ lib/mysql2.rb:9:in require': 126: The specified module could not be found. - C:/RailsInsta ller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2/mysql2.so (Load Error) from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/ lib/mysql2.rb:9:in ' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in block (2 levels) in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:66:in each' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:66:in block in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:55:in each' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:55:in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler.rb:120:in require' from C:/Sites/RP/talk/config/application.rb:9:in require': 126: The specified module could not be found. - C:/RailsInsta ller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2/mysql2.so (Load Error) from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/ lib/mysql2.rb:9:in :in'from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/ require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in bundler-1.0.18 /lib/bundler/runtime.rb:68:in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in :从C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 / lib / bundler / runtime中的require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in块中( require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:68:in 2个级别)。 rb:66:在each' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:66:in在require块中来自C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:55 each' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18 /lib/bundler/runtime.rb:55:in require'来自C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9。 1 /宝石/捆绑-1.0.18 /lib/bundler.rb:120:in require' from C:/Sites/RP/talk/config/application.rb:9:in require' from C:/Sites/RP/talk/config/application.rb:9:in ' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.1.0 /lib/rails/commands.rb:21:in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.1.0 /lib/rails/commands.rb:21:in ' from script/rails:6:in require' from script/rails:6:in ' require' from C:/Sites/RP/talk/config/application.rb:9:in来自C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.1.0 / lib / require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.1.0 /lib/rails/commands.rb:21:in rails / commands.rb:21:in require' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/railties-3.1.0 /lib/rails/commands.rb:21:in 'from script / rails:6:in require' from script/rails:6:in '

http://www.ruby-forum.com/topic/150580 has the answer. http://www.ruby-forum.com/topic/150580有答案。 for some reason I need to: 由于某些原因,我需要:

1/ gem install mysql 2/ copy the libmysql.dll file from /MYSQL/MySQL Server 5.5/lib and paste it to Ruby1.9.2/bin 1 / gem install mysql 2 /从/ MYSQL / MySQL Server 5.5 / lib复制libmysql.dll文件并将其粘贴到Ruby1.9.2 / bin

after that, it is smooth sailing... 之后,航行顺畅...

Even though I did it, I would appreciate if anyone has an insight into the reason behind this: 即使我做到了,也希望有人能了解其背后的原因:

On windows there should be a LIB environment variable. 在Windows上,应该有一个LIB环境变量。 Have you checked to make sure that the path to libmysql has been added to this? 您是否检查过以确保已将libmysql的路径添加到其中? I suspect it hasn't. 我怀疑还没有。

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

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