通过 Bundler 安装 mysql2 gem 时出错

2022-01-18 00:00:00 ruby-on-rails ruby mysql bundler rubygems

我正在尝试通过 Bundler 安装 mysql2 gem,但它一直因以下错误而死:

I am trying to install the mysql2 gem via the Bundler, but it keeps dying with the following error:

** 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.

我通过谷歌搜索找到的大多数东西都建议传递 --with-mysql-config 参数来修复它.所以,基于:

Most things I found via Googling recommended passing the --with-mysql-config parameter to fix it. So, based on:

$ which mysql_config
/usr/bin/mysql_config

我在 Bundler 的配置中添加了以下内容:

I added the following to the Bundler's config:

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

但是,仍然没有运气 - 与上述相同的崩溃.

However, still no luck -- same crash as above.

由于它因 mysql.h is missing 错误而死,我检查了它,据说它在附近,只是无法被 Bundler 找到.

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.

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

有什么想法吗?

推荐答案

答案与 Wrikken 发布的类似——为了未来的读者,我做了以下修正.

Answer was similar to the one Wrikken posted -- here's what I did to fix it for the sake of future readers.

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

执行 sudo yum list installed 将打印出您机器上所有已安装的软件包(注意:RHEL 上的 yum 需要您添加 Red Hat Network 存储库 [我使用 EPEL],并通过 sudo 运行).

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).

我有 mysqlmysql-server,这解释了为什么 MySQL 对每个预先存在的应用程序都很好,但没有 mysql-devel,这是修复 mysql.h is missing 错误和类似的其他构建错误所必需的.

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.

长话短说,在 mysqldump -u root -ppassword --all-databases > 之后full-dump.sql 为了安全起见,它被简单地修复了

Long story short, after a mysqldump -u root -ppassword --all-databases > full-dump.sql for safety, it was fixed with a simple

sudo yum install mysql-devel

相关文章