通过捆绑程序安装mysql2 gem时出错

通过捆绑程序安装mysql2 gem时出错,mysql,ruby-on-rails,ruby,rubygems,bundler,Mysql,Ruby On Rails,Ruby,Rubygems,Bundler,我正试图通过Bundler安装mysql2gem,但它一直死机,出现以下错误: ** executing command /home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::Ex

我正试图通过Bundler安装
mysql2
gem,但它一直死机,出现以下错误:

** executing command
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions': 
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no

-----
mysql.h is missing.  please check your installation of mysql and try again.
-----

*** 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=/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
--with-mysql-config
Gem files will remain installed for inspection.
我通过谷歌搜索找到的大多数东西都建议通过mysql config参数传递
——来修复它。因此,基于:

$ which mysql_config
/usr/bin/mysql_config
我将以下内容添加到Bundler的配置中:

$ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config'
然而,仍然没有运气——和上面一样的崩溃

由于mysql.h丢失了,我检查了一下,据说它就在附近,只是捆绑程序找不到它

$ find / -name mysql.h
/usr/include/mysql5/mysql/mysql.h

有什么想法吗?

答案与Wrikken发布的答案相似——为了未来的读者,我做了如下修改

(这适用于RHEL 5.5——类似但不同的命令适用于Ubuntu/Debian/etc)

执行
sudo-yum-list-installed
将打印出您机器上所有已安装的软件包(注意:RHEL上的
yum
要求您添加一个Red Hat网络存储库[I use],并通过
sudo
运行它)

我有
mysql
mysql服务器
,这解释了为什么mysql对每个预先存在的应用程序都能正常工作,但没有
mysql-devel
,这是修复
mysql.h缺失
错误和类似的其他构建错误所必需的

长话短说,为了安全起见,在一个
mysqldump-u root-ppassword--all databases>full dump.sql之后,它通过一个简单的

sudo yum install mysql-devel

对于Ubuntu,必须安装以下内容。 libmysqlclient开发
libmysqlclient16

我知道这是一个古老的错误,但如果有人仍然收到此zlib错误,请确保键入: rvm使用

(无论您使用什么版本)


我可以发誓是我干的。如果有人把头发拔出来,就发帖子,这很有帮助。如果不是,祝你好运

出现上述问题的原因是您的系统中没有正确安装mysql-devel软件包。我将在接下来的时间里解释如何修复它。当您尝试使用安装该软件包时

    yum install mysql-devel
有时,如果安装MySql管理工具和MySql查询浏览器,则会与安装的现有软件包发生冲突

在这种情况下,您需要卸载所有现有的mysql2软件包,然后重新安装

    rpm -qa -last | grep -i mysql
    yum remove MySQL-server-5.5.27-1.rhel5
    yum remove MySQL-client-5.5.27-1.rhel5
    yum remove mysql-gui-tools-5.0r12-1rhel4
    yum remove mysql-query-browser-5.0r12-1rhel4-a
因此,您可以像上面那样卸载rpm-qa显示的任何mysql内容

然后可以安装mysql服务器和mysql客户端

    yum install mysql-server
    yum install mysql-client
现在安装mysql-devel包

    yum install mysql-devel
现在没有软件包冲突,您可以安装mysql2 gem了

    gem install mysql2 -v '0.3.11'

现在,您的mysql2 gem将成功安装,您可以开始了。

在我的情况下,问题是mysql2配置脚本出现了错误。当命令行使用--cflags选项调用时,它将返回一个包含以下内容的选项字符串:

-Xclang -target-feature -Xclang -aes -Qunused-arguments -Xclang-目标功能-Xclang-aes-使用的参数 出于某种原因,如果包含这些选项,那么在extconf.rb脚本中调用_头('mysql.h')将失败

对我来说,有效的方法是手动编辑mysql_配置文件,从行中删除对这些选项的引用:

cflags="-I$pkgincludedir -Os -w -pipe -march=native -Xclang -target-feature -Xclang -aes -Qunused-arguments -O2 -g -DDBUG_OFF " #note: end space! cflags=“-I$pkgincludedir-Os-w-pipe-march=native-Xclang-target feature-Xclang-aes-qused arguments-O2-g-DDBUG_OFF”#注意:结束空间! 我将其改写为:

cflags="-I$pkgincludedir -Os -w -pipe -march=native -O2 -g -DDBUG_OFF " #note: end space!
cflags=“-I$pkgincludedir-Os-w-pipe-march=native-O2-g-DDBUG#u OFF”#注意:结束空间 对于安装了brew mysql的Mac,以下解决方案为我解决了这个问题:

我在/usr/local/ceral/mysql/5.6.12/bin中编辑了mysql_config文件,并删除了用于cflags和cxflags的W-compiler选项-Wno null conversion和-Wno unused private字段

这解决了“gem安装mysql2”的问题


参考资料:

我在fedora 23上为redmine安装捆绑包时遇到了这个问题。我找到的解决方案是发出这个命令-
sudo dnf install redhat rpm config


这不仅解决了我在安装mysql2时遇到的问题,还解决了nokogiri和Red地毯的问题。

我也遇到了同样的错误。对于ubuntu 16。我必须写下以下命令:

sudo apt-get install libmysqlclient-dev 
在运行mysql版本15.1发行版10.0.34-MariaDB的Ubuntu16.04.4 LTS上,对于使用readline 5.2的debian linux gnu(x86_64),以下工作正常:

sudo apt-get install libmariadb-client-lgpl-dev
我看到,当前安装程序的错误消息建议运行

apt-get install libmysqlclient-dev

这可能也行。

您是否在尝试过该解决方案?否则,您可能只需编辑
ext/mysql2/extconf.rb
并自己输入mysql目录的正确路径(接近顶部)。在mac中,在我的安装中安装了
mysql-devel
,但是
/usr/include/mysql
是空的
mysql.h
位于
/usr/include/mysql51
中。所以我运行了
sudormdir/usr/include/mysql;sudo ln-s/usr/include/mysql51/usr/include/mysql
瞧!Mysql2现在可以正常构建了。其他人可以找到这个答案:**extconf.rb失败了***(fedora也适用)我也是!谢谢你,救了我一天!当我在Ubuntu16.04上尝试时,没有
libmysqlclient16
,只有
libmysqlclient20
。我怀疑无论你使用什么版本的Ubuntu,比如
sudo apt get install'libmysqlclient*”
都会安装所需的两个软件包,只要更新后的版本不会破坏任何东西。非常感谢。唯一有帮助的解决办法。