mysql - 带有 xampp + rails + mysql2 gem 的 OS X Lion

标签 mysql ruby ruby-on-rails-3 xampp mysql2

我一直在努力弄清楚如何让 OS X Lion 与 XAMPP 安装的 MySQL 一起使用 rails 中的 mysql2 gem。

这是我尝试过的:

  • 安装了 XAMPP 开发工具包
  • 用 port 和 brew 安装了 mysql5-server。这两个我现在都卸载了。因为它没有解决问题。
  • 从 DMG 文件安装了 mysql5 社区版。现在已卸载,因为它没有解决问题。
  • 下载 32 位版本的 mysql5 社区版作为 tar。解压文件夹到'/var/mysql'

这是我正在运行以尝试安装它的命令:

gem install mysql2 -- --with-mysql-dir=/var/mysql --with-mysql-include=
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config=
/Applications/XAMPP/xamppfiles/bin/mysql_config

我不知道如何让它工作。我唯一能想到的是我不知何故没有正确指向目录。我尝试从 with-mysql-include、with-mysql-dir 和 with-mysql-lib 配置选项中删除/include/、/mysql/和/lib/。没有运气。我试过将它们指向 XAMPP 安装。仍然没有运气。

返回的错误是:

ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-mysql-dir=/var/mysql --with-mysql-include=/var/mysql/include --with-mysql-lib=/var/mysql --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
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/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    --with-mysql-config


Gem files will remain installed in /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

最佳答案

最好不要理会 XAMPP 提供的东西,只安装一个新的 MySQL 副本,并简化安装 mysql2 的 Gem 命令:

brew install mysql
gem install mysql2

由于以下原因,您在通过 Homebrew 安装 MySQL 后安装 gem 时遇到错误:

--with-mysql-dir=/var/mysql --with-mysql-include= \
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config= \
/Applications/XAMPP/xamppfiles/bin/mysql_config

所以删除它就解决了问题。

关于mysql - 带有 xampp + rails + mysql2 gem 的 OS X Lion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11281628/

相关文章:

html - 如何在 Rails3 中解析上传的 txt 文件

javascript - 预编译 application.js 资源

mysql - MySQL 中的 JSON_SET 和 JSON_EXTRACT 是原子的吗?

mysql - 一张表用于多个 hasman 关系

Ruby - 如何使用 Logger 限制文件大小来创建日志文件?

javascript - 嵌套 Rails 模型 - 在创建时忽略 child_index

ruby - class_eval 和 class << className 有什么区别?

ruby-on-rails - Rails - 具有多个数据库的相同模型(只读)

php - 遍历二叉树的递归函数

Mysql 比较两个数据库表和字段