Ruby on Rails,“无法启动此程序,因为计算机中丢失LIBMYSQL.dll”问题解决
http://blog.csdn.net/abbuggy/article/details/7405192
我的电脑使用Ruby on Rails与MySQL连接时,会提示“无法启动此程序,因为计算机中丢失LIBMYSQL.dll。尝试重新安装程序以解决此问题”(This application has failed to start because LIBMYSQL.DLL was not found.)的错误。
软件版本:
Win7 64位 E:\greensoft\RailsInstaller>mysql -v Server version: 5.5.17 MySQL Community Server (GPL) E:\greensoft\RailsInstaller>ruby -v ruby 1.9.3p125 (2012-02-16) [i386-mingw32] E:\greensoft\RailsInstaller>rails -v Rails 3.2.1 E:\greensoft\RailsInstaller>gem list mysql2 mysql2 (0.3.11 x86-mingw32)
尝试过将MySQL\MySQL Server 5.5\lib下的libmysql.dll和libmysql.lib拷贝到Ruby/bin中。报错换成
E:\greensoft\RailsInstaller\Sites\simple_site>rails server E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': 193: %1 不是有效的 Win32 应用程序。 - E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError) from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:in `require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:in `<top (required)>' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `block (2 levels) in require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `block in require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler.rb:122:in `require' from E:/greensoft/RailsInstaller/Sites/simple_site/config/application.rb:7:in `<top (required)>' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:53:in `block in <top (required)>' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap' from E:/greensoft/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>后来才知道这是由于32位的Ruby与64位的MySQL的不兼容造成的。
不用重装操作系统,也不用重装MySQL,使用32位的MySQL connector来屏蔽这些问题。下载时请看清32位windows的zip版本。
http://dev.mysql.com/downloads/connector/c/
下载下来解压缩,将lib目录下的libmysql.dll和libmysql.lib拷贝到Ruby/bin目录下。问题解决!
E:\greensoft\RailsInstaller\Sites\simple_site>rails server => Booting WEBrick => Rails 3.2.1 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-03-29 00:33:30] INFO WEBrick 1.3.1 [2012-03-29 00:33:30] INFO ruby 1.9.3 (2012-02-16) [i386-mingw32] [2012-03-29 00:33:30] INFO WEBrick::HTTPServer#start: pid=4596 port=3000