使用MAMP 2.2在Mac上“gem install mysql2”

时间:2014-01-05 15:16:31

标签: mysql ruby-on-rails macos gem mamp

当我尝试在当前目录(这是一个新的rails项目)中运行rails server时,它说我需要安装mysql2 gem。起初,我不知道这意味着什么......然后,我做了一些戳,最后决定安装宝石。但是,我得到了这个超级麻烦的错误(因为我只花了2个小时试图调查,并解决了另一个错误)。我处于放弃的边缘,但我真的想试试铁轨。请帮忙!

目前,如果我运行sudo gem install mysql2,或者有些人告诉我在线做gem install mysql -- \ --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config(我有MAMP),它会给我以下错误:

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

    /Users/vicky/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /Applications/MAMP/Library/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /Applications/MAMP/Library/lib
-----
creating Makefile

make "DESTDIR="
compiling client.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/mpapis/.sm/pkg/active/lib'
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1


Gem files will remain installed in /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14 for inspection.
Results logged to /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/ext/mysql2/gem_make.out

1 个答案:

答案 0 :(得分:6)

您是否考虑过使用自制软件安装MySQL(http://brew.sh/)? MAMP代表Mac-Apache-MySQL-PHP(其中最重要的部分是最重要的)。我建议你直接在你的盒子上安装MySQL(自制软件可以处理所有繁重的工作),然后我怀疑你在安装这个宝石时会遇到什么困难。

安装自制软件 -

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

按照任何说明运行brew doctor然后安装MySQL运行brew install mysql并按照其提供的任何说明来设置用户等...

=============更新==============

所以,你要做的就是使用brew这种方式来安装MySQL,然后以正常方式安装gem - sudo gem install mysql2假设这样可行,那么你将能够切换回旧版本MySQL通过MAMP安装 -

sudo nano /etc/paths

然后将此行添加到文档的顶部 -

/Applications/MAMP/Library/bin

重新启动终端,然后运行mysql以仔细检查您是否正在使用MySQL的MAMP安装,并且您将会很高兴。