Rails cannot generate model using mysql

倾然丶 夕夏残阳落幕 提交于 2019-12-13 05:19:27

问题


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)


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. 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' 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:inblock (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:inblock 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:inrequire' 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' 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'


回答1:


http://www.ruby-forum.com/topic/150580 has the answer. 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

after that, it is smooth sailing...

Even though I did it, I would appreciate if anyone has an insight into the reason behind this:




回答2:


On windows there should be a LIB environment variable. Have you checked to make sure that the path to libmysql has been added to this? I suspect it hasn't.



来源:https://stackoverflow.com/questions/8205817/rails-cannot-generate-model-using-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!