Rails cannot generate model using mysql

2019-09-16 13:15发布

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'

2条回答
Root(大扎)
2楼-- · 2019-09-16 14:01

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.

查看更多
不美不萌又怎样
3楼-- · 2019-09-16 14:08

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:

查看更多
登录 后发表回答