'require':无法加载此类文件--mysql(LoadError)

时间:2014-04-13 21:27:14

标签: mysql ruby require

当我尝试运行ruby文件时#34; ruby DisplayWishes.rb"我收到一个require load错误。 我安装了以下mysql软件包,看看它是否有用,目前没有任何效果:

 sudo apt-get install ruby-mysql
 sudo apt-get install ruby-mysql2

/usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in 'require':cannot load such file -- mysql(LoadError) 
 from /usr/local/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
 from DisplayWishes.rb:3:in '<main>'

当我尝试gem安装mysql&amp; mysql2

sudo gem install mysql2
Fetching: mysql2-0.3.15.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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.

2 个答案:

答案 0 :(得分:0)

我在freebsd上遇到了这个问题,并通过运行安装了所需的库:

pkg_add -rv mysql56-client

然后我就可以安装mysql和mysql2 gems。

答案 1 :(得分:0)

这是由于mysql客户端丢失了。

安装以下客户端,问题将解决

apt-get install libmysqlclient-dev