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

当我尝试在我当前的目录(这是一个新的rails项目)中运行rails server时,它说我需要安装mysql2 gem。 起初,我不知道这意味着什么……然后,我做了一些戳,最后决定安装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 

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

安装自制软件 –

 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假设这样可行,那么你将能够通过MAMP切换回旧的MySQL安装通过 –

 sudo nano /etc/paths 

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

 /Applications/MAMP/Library/bin 

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