Ruby 在mac上安装mysql2 gem rails

Ruby 在mac上安装mysql2 gem rails,ruby,rubygems,mysql2,Ruby,Rubygems,Mysql2,我正在尝试安装mysql2的gem,但它似乎找不到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 installi

我正在尝试安装mysql2的gem,但它似乎找不到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

在构建本机扩展时,
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做了哪些更改;)


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

我会安装brew,但我只是想知道它是否会与我现有的XAMPP的mysqlXAMPP的mysql实例的安装冲突,只有在运行它时才会出现。因此,如果您退出它,它不应该与brew的mysql冲突。要使两者同时运行,您可以更改XAMPP one的端口。另外,请务必在
brew安装mysql
后查看说明。它指向了一些信息,比如如何在启动后自动启动、停止和运行mysql。