Moh*_*ain 3 ruby mysql macos ruby-on-rails
我尝试了类似问题的每个解决方案:
最近,我从ubuntu转移到Mac,我试图在Sierra上安装mysql gem,之后我安装了Ruby,Rails,Mysql,
我也打字brew install mysql,它适用于下载mysql,但不是宝石,所以我的问题不相似.
我输入了这个 mysql --version
我得到了 mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper
我试图安装mysql2 gem for rails来构建一个新的应用程序
我输入了这个sudo gem install mysql2并得到了这个错误:
Password:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/mohammed.elias/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170102-2045-18gcs95.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in 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 /usr/local/Cellar/mysql/5.7.16/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/mkmf.log
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysq l2-0.4.5 for inspection.
Results logged to /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/gem_make.out
Run Code Online (Sandbox Code Playgroud)
在新的 Macbook Pro Sierra 上安装 MySQL2 gem 时遇到了完全相同的问题。
您需要更改环境变量以包含以下内容(只需将 0.0.00 替换为所需的 MySQL2 gem 版本:
gem install mysql2 -v '0.0.00' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
Run Code Online (Sandbox Code Playgroud)
此外,您$PATH应该使用带有 bash 配置文件的 mysql 进行设置,这是每次 bash 启动时将运行的设置列表。您的 bash 配置文件可以在您的主目录中的 filename 下找到.bash_profile。如果没有创建,您可以使用命令创建文本文件nano .bash_profile(您应该在您的主目录 (~) 中)。将此添加到您的 bash 配置文件中:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
此行会将上述目录添加到您的路径中,包括 mysql 路径。确保重新启动终端,因为 .bash_profile 仅在终端初始加载时运行。