用windows安装mysql2时出错
Posted
技术标签:
【中文标题】用windows安装mysql2时出错【英文标题】:Error installing mysql2 with windows 【发布时间】:2011-11-23 12:57:33 【问题描述】:奇怪的是我可以用这个命令安装mysql2:
$ gem install mysql2 --platform=ruby -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'
结果如下:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.10
1 gem installed
Installing ri documentation for mysql2-0.3.10...
Installing RDoc documentation for mysql2-0.3.10...
但是当我运行bundle install
(显然我需要安装很多gem)时,安装mysql2失败,所以bundle install
停在那里,这真的让我发疯......任何人都可以帮忙?非常感谢!
以下是来自bundle install
的结果:
Installing mysql2 (0.3.8) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.
c:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=$opt-dir/include
--with-opt-lib
--without-opt-lib=$opt-dir/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=c:/Ruby192/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=$mysql-dir/include
--with-mysql-lib
--without-mysql-lib=$mysql-dir/lib
--with-libmysqllib
--without-libmysqllib
Gem files will remain installed in G:/Desktop/20090319-/Rails Examples/ClockingI
T/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.8 for inspection.
Results logged to G:/Desktop/20090319-/Rails Examples/ClockingIT/vendor/bundle/r
uby/1.9.1/gems/mysql2-0.3.8/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.8), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.8'` succeeds before bundling.
【问题讨论】:
看起来 Bundler 正在尝试安装 mysql2 版本 0.3.8,但据我所知,0.3.8 的 Windows 版本已被删除。我有点困惑,因为它应该与 0.3.10 的行为相同,但无论如何您都可以尝试为 Gemfile 提供一个显式版本。喜欢gem 'mysql2', '0.3.10'
或gem 'mysql2', '0.3.9'
。我会选择后者,因为它有官方的 x86-mingw32 版本。
【参考方案1】:
在我的 ubuntu 机器上,必须先运行 apt-get install libmysqld-dev
,然后运行 gem install mysql2
...它就像一个魅力 :)
【讨论】:
【参考方案2】:尝试从包外部安装 mysql,如果可行,请从 Gemfile 中删除 mysql
sudo gem install mysql --no-rdoc --no-ri --
--with-mysql-config=/usr/local/mysql/bin/mysql_config
还有
apt-get install libmysqld-dev
【讨论】:
我试过gem install mysql
,它成功了,但是当我运行bundle install
时,又出现错误:使用本机扩展安装mysql2(0.3.7) Gem::Installer::ExtensionBuildError: ERROR : 无法构建 gem 原生扩展。 c:/Ruby192/bin/ruby.exe extconf.rb 检查 rb_thread_blocking_region()... 是 检查 main() 在 -llibmysql... 否 *** extconf.rb 失败 ***【参考方案3】:
您尝试安装的 mysql2 gem 版本在 Windows 上存在问题。
请安装mysql2 gem,不注明版本:
gem install mysql2
【讨论】:
runninggem install mysql2
,我得到这个错误:错误:执行 gem ... (NameError) 未初始化常量 Psych::Syck
现在你已经直接安装了mysql,你可以从fgem文件中删除mysql,然后bundle install ok!!!应该够了
谢谢,我使用gem uninstall mysql
和gem uninstall mysql2
删除,然后运行bundle install
,所有gem 都正常,我可以看到mysql2 也安装了Installing mysql2 (0.2.6)
。但是当我运行rake db:migrate
时,我又遇到了问题:libmysql.dll not found
问题,我通过将libmysql.dll
从C:\Program Files\MySQL\MySQL Server 5.5\lib
复制到c:\Ruby192\bin
来修复,然后我运行rake db:migrate
,又遇到了问题:rake aborted! 193: %1 is not a valid Win32 application. - c:/Ruby192/lib/ruby/gems/1.9.1/gem s/mysql2-0.2.6-x86-mingw32/lib/mysql2/1.9/mysql2.so
修复了引用此链接***.com/questions/1208029/… 的%1 is not a valid Win32 application
问题。新问题再次发生...ERROR: ActiveRecord oracle_enhanced adapter could not load ruby-oci8 library
,调用堆栈:c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.2/l ib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:7:in
res cue in 工作正常,请下载版本mysql-connector-c-6.1.5-win32,解压到文件夹,试试这个。
很适合我。
gem install mysql2 --no-ri --no-rdoc --platform=ruby --with-mysql-include=C:\mysql-connector\mysql-connector-c-6.1.5-win32\包括 --with-mysql-lib=C:\mysql-connector\mysql-connector-c-6.1.5-win32\lib
【讨论】:
以上是关于用windows安装mysql2时出错的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Ubuntu 16.04 上安装 mysql2 [错误:安装 mysql2 时出错:错误:无法构建 gem 本机扩展。] [重复]
在 Ubuntu 20.04 上安装 mysql2 gem 版本“0.3.21”时出错
错误:安装 mysql2 时出错:错误:无法在 AWS Linux 上构建 gem 原生扩展