2

我正在尝试执行 mysql2 的 gem install,但看起来它没有找到 mysql 的安装位置。我在我的 Mac 上使用 XAMPP 堆栈安装了 mysql。我阅读了其他帖子,但没有产生任何结果。

sudo  gem install mysql2 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config 
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-mysql-config


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11 for inspe
4

1 回答 1

1

在构建本机扩展时,gem正在寻找 mysql 标头。这些可能在/Application/XAMPP/...其中,您可以通过以下参数指向它们gem-

--with-mysql-dir=/path/to/mysql \
--with-mysql-include=/path/to/mysql/headers \
--with-mysql-lib=/path/to/lib \
--with-mysql-config=/path/to/configs

或者,如果不需要使用 XAMPP 的 mysql,您可以通过自制软件获取 mysql ,然后 -

brew install mysql 
gem install mysql2

我更喜欢第二种方式。它更干净,更不容易混淆,因为我不知道 XAMPP 对其捆绑的 mysql 做了什么更改;)

Later if you need to setup such gems on a linux vps, and encounter similar issues, remember to install the -dev packages. E.g. libmysqlclient-dev for mysql.

于 2012-10-10T03:26:43.360 回答