2012-10-10 120 views
2

我正在尝试执行mysql2的gem安装,但它看起来好像没有找到mysql的安装位置。我在我的Mac上使用XAMPP堆栈安装了mysql。我读了其他职位,但屈服于没有结果。在mac上安装mysql2 gem rails

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 

回答

1

在构建本机扩展时,gem正在查找mysql标头。这些可能是在/Application/XAMPP/...,你可以通过以下ARGS指向他们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的是没有必要的,你可以通过homebrew,然后让MySQL -

brew install mysql 
gem install mysql2 

我宁愿第二种方式。因为我不知道XAMPP对其捆绑的mysql做了什么更改;)

如果您需要在linux vps上设置此类gem并遇到类似问题,请记住安装-dev软件包。例如。 mysql的libmysqlclient-dev

+0

我会做brew安装,但我只是想知道它是否会与我现有的XAMPP的mysql安装冲突 – tawheed

+0

XAMPP的mysql实例只有在运行时才会出现。所以如果你退出它,它不应该与brew的mysql冲突。要使它们一起运行,您可以更改XAMPP的端口。另外,在'brew install mysql'之后,请查看指令。它指向如下信息 - 如何在启动后自动启动,停止和运行mysql。 –