【问题标题】:'require': cannot load such file --mysql ( LoadError )'require':无法加载此类文件--mysql(LoadError)
【发布时间】:2014-05-27 17:42:23
【问题描述】:

当我尝试运行一个 ruby​​ 文件“ruby DisplayWishes.rb”时,我收到一个要求加载错误。 我安装了以下 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 install mysql & 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.

【问题讨论】:

  • 你安装了 MySQL gem 和 MySQL Server 吗?
  • 我安装了 mysql 服务器,但我认为我没有安装 mysql gem。
  • 只是让你知道,它不是 ruby​​ on rails。
  • gem install mysql &amp;&amp; gem install mysql2
  • 我在尝试安装两者时收到错误消息。 extconf.rb 失败 - 由于某种原因无法创建 makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项

标签: mysql ruby require


【解决方案1】:

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

pkg_add -rv mysql56-client

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

【讨论】:

    【解决方案2】:

    这是由于缺少mysql客户端。

    安装以下客户端即可解决问题

    apt-get install libmysqlclient-dev
    

    【讨论】:

      猜你喜欢
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多