繁体   English   中英

mysql2 gem 无法在带有 Homebrew 的 OS X 上使用 MySQL 5.6.12 进行编译

[英]mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew

我更新了我用 Homebrew 安装的所有软件包。 MySQL 升级到 5.6.12(从 5.5.27 左右):

$ mysql --version
mysql  Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using  EditLine wrapper

现在 mysql2 gem 不再编译:

$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

        /Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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
    --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=/Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby
    --with-mysql-config
    --without-mysql-config

文件mysql.h存在于/usr/local/Cellar/mysql/5.6.12/include/mysql.h 任何想法发生了什么?

文件mysql.h没有出现在/usr/local因为符号链接似乎比它应该更深:

$ ls -la /usr/local/include/mysql
lrwxr-xr-x  1 pupeno  admin  36 21 Jun 15:18 /usr/local/include/mysql@ -> ../Cellar/mysql/5.6.12/include/mysql

代替

/usr/local/Cellar/mysql/5.6.12/include

话虽如此,我手动修复了符号链接,但编译仍然失败。 所以我被困住了。

我遇到了同样的问题,我设法解决了它。 我做了很多事情,我不确定它是什么,但是使用 MySQL 5.6.10 似乎已经奏效了。

卸载 MySQL 5.6.12:

brew unlink mysql
brew uninstall mysql

进入自制软件目录:

cd /usr/local

转到版本 5.6.10(您可以通过运行brew versions mysql找到版本列表:

git checkout 48f7e86 Library/Formula/mysql.rb

然后再次安装mysql:

brew install mysql

现在gem install mysql2对我gem install mysql2

我还从源代码brew install mysql --build-from-sourcebrew install mysql --build-from-source ),但这并没有解决它,但可能是解决方案的一部分。

只是;)

gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config

这似乎也对我有用。 它强制 gem 针对 5.6.10 进行编译。

bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config

相关答案: https : //stackoverflow.com/a/9360181

这里的最佳答案已经过时了……酿酒商已经修复了 mysql:

brew update
brew upgrade mysql
gem install mysql2

这会将 mysql 更新到最新版本,这似乎与 OSX 上的 mysql2 gem 一起工作正常。

我不得不指定ldflagscppflags为它正确编译,就像这样:

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

有很多更新的 MySQL 版本可用,但对于在 Mac OS X Mojave 上安装的旧项目,我仍然需要运行 MySQL 5.6 并在 Rails 5 应用程序中链接它。

我配置了 bundler,然后安装了 bundle,一切顺利。

$> brew install mysql@5.6
$> bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql\@5.6/5.6.42/bin/mysql_config
$> bundle install

请注意,您需要更新路径中的 MySQL 发行版本。

我会推荐这个答案: mysql2 gem failed to compile with MySQL 5.6.12 on OS X with Homebrew

问题在于 Homebrew 版本的 MySql 中的编译器设置。 原始答案在这里找到: http : //www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM