MySQL 通过 Bundler 安装 mysql2 gem 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3754662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Errors Installing mysql2 gem via the Bundler
提问by T.J. Schuck
I am trying to install the mysql2
gem via the Bundler, but it keeps dying with the following error:
我正在尝试mysql2
通过 Bundler安装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. So, based on:
我通过谷歌搜索发现的大多数东西都建议传递--with-mysql-config
参数来修复它。所以,基于:
$ 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 missing
,我检查了它,据称它在附近,只是 Bundler 找不到。
$ find / -name mysql.h
/usr/include/mysql5/mysql/mysql.h
Any thoughts?
有什么想法吗?
回答by T.J. Schuck
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/等。)
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
会打印出您机器上所有已安装的软件包(注意:yum
在 RHEL 上需要您添加一个 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.
我有mysql
和mysql-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
回答by Indika K
For Ubuntu have to install following. libmysqlclient-dev libmysqlclient16
对于 Ubuntu 必须安装以下。libmysqlclient-dev libmysqlclient16
回答by guido
For Mac with a brew install of mysql the following solution fixed the problem for me:
对于使用 brew 安装 mysql 的 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 文件,并删除了 cflags 和 cxxflags 的 W 编译器选项 -Wno-null-conversion 和 -Wno-unused-private-field。
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
回答by maniempire
The above problem will be occured because the mysql-devel package is not properly installed in your system. I will be explain the same in Centos of how to fix it. When you try to install that package using,
出现上述问题是因为你的系统没有正确安装mysql-devel包。我将在 Centos 中解释如何修复它。当您尝试使用安装该软件包时,
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.
如果您安装 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 将成功安装,您可以开始使用了。
回答by user2449437
In my case the problem was a misbehaving mysql_config script. When invoked by the command line with the --cflags option it would return a string of options containing:
在我的情况下,问题是行为不当的 mysql_config 脚本。当由带有 --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!
回答by Manish Shrivastava
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.
它可以恢复。
回答by Matthias Luh
On my Ubuntu 16.04.4 LTSrunning 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,对于 debian-linux-gnu (x86_64) 使用 readline 5.2,以下工作:
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.
这也可能有效。
回答by zillaofthegods
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 的问题。
回答by Kevin
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. :)
我可以发誓我做到了。只是张贴以防万一有人把头发拉出来,这会有所帮助。如果运气不好。:)