简体   繁体   English

错误通过Bundler安装mysql2 gem

[英]Errors Installing mysql2 gem via the Bundler

I am trying to install the mysql2 gem via the Bundler, but it keeps dying with the following error: 我试图通过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.

Most things I found via Googling recommended passing the --with-mysql-config parameter to fix it. 我通过Google搜索找到的大多数内容都建议传递--with-mysql-config参数来修复它。 So, based on: 所以,基于:

$ which mysql_config
/usr/bin/mysql_config

I added the following to the Bundler's config: 我在Bundler的配置中添加了以下内容:

$ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config'

However, still no luck -- same crash as above. 然而,仍然没有运气 - 与上面相同的崩溃。

Since it's dying with the error mysql.h is missing , I checked for that, and it's allegedly around, just can't be found by the Bundler. 由于它mysql.h is missingmysql.h is missing的错误,我检查了它,并且它据称在周围,但是Bundler找不到。

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

Any thoughts? 有什么想法吗?

Answer was similar to the one Wrikken posted -- here's what I did to fix it for the sake of future readers. 答案类似于Wrikken发布的答案 - 这就是我为了未来读者而采取的措施。

(This is for RHEL 5.5 -- similar but different commands apply for Ubuntu/Debian/etc.) (这适用于RHEL 5.5 - 类似但不同的命令适用于Ubuntu / Debian / etc.)

Doing sudo yum list installed will print out all installed packages on your machine (note: yum on RHEL requires you add a Red Hat Network repository [I use EPEL ], and run it via sudo ). sudo yum list installed会打印出你机器上所有已安装的软件包(注意:RHEL上的yum要求你添加一个Red Hat Network存储库[我使用EPEL ],并通过sudo运行它)。

I had mysql and mysql-server , which explained why MySQL worked fine for every pre-existing app, but no mysql-devel , which is necessary to fix that mysql.h is missing error and similar other build errors. 我有mysqlmysql-server ,它解释了为什么MySQL适用于每个预先存在的应用程序,但没有mysql-devel ,这是修复mysql.h is missing错误和类似的其他构建错误所必需的。

Long story short, after a mysqldump -u root -ppassword --all-databases > full-dump.sql for safety, it was fixed with a simple 长话短说,在一个mysqldump -u root -ppassword --all-databases > full-dump.sql为了安全起见,它修复了一个简单的

sudo yum install mysql-devel

For Ubuntu have to install following. 对于Ubuntu必须安装以下。 libmysqlclient-dev libmysqlclient16 libmysqlclient-dev libmysqlclient16

For Mac with a brew install of mysql the following solution fixed the problem for me: 对于使用mysql的brew安装的Mac,以下解决方案为我解决了这个问题:

I edited the mysql_config file in /usr/local/Cellar/mysql/5.6.12/bin and removed the W-compiler options -Wno-null-conversion and -Wno-unused-private-field for cflags and cxxflags. 我编辑了/usr/local/Cellar/mysql/5.6.12/bin中的mysql_config文件,并删除了W-compiler选项-Wno-null-conversion和-Wno-unused-private-field for cflags和cxxflags。

This solved the problem with "gem install mysql2". 这解决了“gem install mysql2”的问题。

Reference: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html 参考: http//www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

The above problem will be occured because the mysql-devel package is not properly installed in your system. 由于mysql-devel软件包未在您的系统中正确安装,因此会出现上述问题。 I will be explain the same in Centos of how to fix it. 我将在Centos中解释如何修复它。 When you try to install that package using, 当您尝试使用时安装该程序包

    yum install mysql-devel

somtimes there will be some clash occurs with the existing packages that gets installed if you install the MySql-Administrative tool and MySQL query browser. somtimes如果你安装了MySql-Administrative工具和MySQL查询浏览器,那么现有的软件包会发生一些冲突。

In that case, you need to uninstall all the existing mysql2 packages and install it again. 在这种情况下,您需要卸载所有现有的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

So, you can uninstall whatever mysql things displayed with rpm -qa as like above. 因此,您可以卸载rpm -qa显示的任何mysql内容,如上所示。

Then you can install the mysql-server and mysql-client. 然后你可以安装mysql-server和mysql-client。

    yum install mysql-server
    yum install mysql-client

Now you do the installation of mysql-devel package. 现在你安装mysql-devel包。

    yum install mysql-devel

Now there is no package clashes and you can able to install the mysql2 gem. 现在没有包冲突,你可以安装mysql2 gem。

    gem install mysql2 -v '0.3.11'

Now your mysql2 gem will be successfully installed and you are good to go. 现在你的mysql2 gem将成功安装,你很高兴。

In my case the problem was a misbehaving mysql_config script. 在我的情况下,问题是一个行为不当的mysql_config脚本。 When invoked by the command line with the --cflags option it would return a string of options containing: 当命令行使用--cflags选项调用时,它将返回一个包含以下内容的选项字符串:

-Xclang -target-feature -Xclang -aes -Qunused-arguments

For some reason the call to have_header('mysql.h') in the extconf.rb script would fail if those option were included. 出于某种原因,如果包含这些选项,则在extconf.rb脚本中调用have_header('mysql.h')会失败。

What worked for me was to hand edit the mysql_config file removing the reference to those options from the line: 对我有用的是手动编辑mysql_config文件,从行中删除对这些选项的引用:

cflags="-I$pkgincludedir -Os -w -pipe -march=native -Xclang -target-feature -Xclang -aes -Qunused-arguments  -O2 -g -DDBUG_OFF " #note: end space!

which I rewrote as: 我改写为:

cflags="-I$pkgincludedir -Os -w -pipe -march=native  -O2 -g -DDBUG_OFF " #note: end space!

I got the same error. 我得到了同样的错误。 and for ubuntu 16. I had to write below command: 对于ubuntu 16.我必须在下面写命令:

sudo apt-get install libmysqlclient-dev 

and it work back. 它回来了。

I ran into this issue while bundle installing for redmine on fedora 23. The solution I found was to issue this command - sudo dnf install redhat-rpm-config . 我遇到了这个问题,同时在fedora 23上安装了redmine。我找到的解决方案是发出这个命令 - sudo dnf install redhat-rpm-config

Not only did this fix my issue with installing mysql2, but also for nokogiri and redcarpet. 这不仅解决了我安装mysql2的问题,也解决了nokogiri和redcarpet的问题。

On my Ubuntu 16.04.4 LTS running mysql Ver 15.1 Distrib 10.0.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 , the following worked: 在我的Ubuntu 16.04.4 LTS上运行mysql Ver 15.1 Distrib 10.0.34-MariaDB,对于使用readline 5.2的debian-linux-gnu(x86_64) ,以下工作:

sudo apt-get install libmariadb-client-lgpl-dev

I saw, that the error message of the current installer suggests running 我看到,当前安装程序的错误消息表明正在运行

apt-get install libmysqlclient-dev

This might work as well. 这可能也有效。

I know this is ancient, but if anyone still gets this zlib error, make certain that you typed: rvm use 我知道这很古老,但如果有人仍然得到这个zlib错误,请确保你输入:rvm use

(whatever version you're using) (无论你使用什么版本)

I could have sworn I did that. 我可以发誓我做到了。 Just posting in case anyone is pulling their hair out and this helps. 只是张贴以防万一有人拉他们的头发,这有帮助。 If not good luck. 如果没有好运。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM