MySQL gem安装mysql失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5795309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:39:28  来源:igfitidea点击:

gem install mysql fail

mysqlruby-on-railsrubymacosrubygems

提问by Kyle

I've followed the instructions on http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/, including the installation of ruby via macport.

我已按照http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/上的说明进行操作,包括通过 macport 安装 ruby​​。

Whenever I execute gem install mysql, I'll get the following error

每当我执行gem install mysql 时,都会出现以下错误

bash-3.2# gem install mysql
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /opt/local/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** 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=/opt/local/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

How can I resolve this issue ? I've installed the 32-bit mysql using the package file (.pkg) and also, I'm extremely new to ruby...

我该如何解决这个问题?我已经使用包文件 (.pkg) 安装了 32 位 mysql,而且,我对 ruby​​ 非常陌生......

Update 4/26/11 5:11pm ESTInstalled RVM and updated ruby to 1.9.2 Also I have looked through the links posted on the comments. I did locate mysql_configand results were

2011 年 4 月 26 日下午 5 点 11 分更新 EST安装了 RVM 并将 ruby​​ 更新到 1.9.2 此外,我还查看了评论中发布的链接。我做了locate mysql_config,结果是

/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config
/usr/local/mysql-5.1.56-osx10.6-x86/man/man1/mysql_config.1

Hence, I tried gem install mysql - -with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_configbut it still doesn't work... I did get new error information however..

因此,我试过了, gem install mysql - -with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config但它仍然不起作用......但是我确实得到了新的错误信息......

/Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:440:in `try_link'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:552:in `try_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:797:in `block in have_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:796:in `have_func'
    from extconf.rb:50:in `<main>'


Gem files will remain installed in /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/bin/th-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config/gems/mysql-2.8.1 for inspection.

Really wish to thank those who commented... and really appreciate if more help can be given..... been trying to get the darn mysql installed for 2 days...

真的要感谢那些评论的人......如果可以提供更多帮助,真的很感激......一直试图安装 mysql 2 天......

采纳答案by Kyle

Solved the problem by uninstalling 32-bit MySQL thats on my system.. and installed 5.1.56 64-bit.

通过卸载我系统上的 32 位 MySQL 解决了这个问题......并安装了 5.1.56 64 位。

Hope this is helpful to others who's having the same problem as me..

希望这对和我有同样问题的其他人有帮助。。

回答by Vicky

The program 'mysql_config' is currently not installed. You can install it by typing:

当前未安装程序“mysql_config”。您可以通过键入以下内容来安装它:

$ sudo apt-get install libmysqlclient-dev
$ bundle install

bundle show [mysql2] # To find the location.

回答by Mike Farmer

Try this:

尝试这个:

gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config

(Note the extra dashes)

(注意额外的破折号)

If that doesn't work, I highly recommend going with the homebrew installation mentioned above of MySQL. You can read about a soup-to-nuts installation here: Uninstall Ruby on Rails on Mac OS X 10.6

如果这不起作用,我强烈建议您使用上面提到的 MySQL 自制软件安装。您可以在此处阅读完整的安装:在 Mac OS X 10.6 上卸载 Ruby on Rails

回答by tk120404

I had the same issue in Cent OS, but got it resolved by installing mysql-devel

我在 Cent OS 中遇到了同样的问题,但是通过安装 mysql-devel 解决了

 yum install mysql mysql-server mysql-devel

回答by James McMahon

Based on this answerI ended up editing my /usr/local/Cellar/mysql/5.6.12/bin/mysql_configfile to remove -Wno-null-conversion -Wno-unused-private-field, which is what the error the mkmf.log was complaining about.

基于这个答案,我最终编辑了我的/usr/local/Cellar/mysql/5.6.12/bin/mysql_config文件以 remove -Wno-null-conversion -Wno-unused-private-field,这就是 mkmf.log 抱怨的错误。

My setup is Mac OSX with Ruby installed using RVM and MySQL installed using homebrew.

我的设置是 Mac OSX,使用 RVM 安装 Ruby,使用自制软件安装 MySQL。

回答by knowuh

If you are using bundleryou can set build parameters for your gems by using bundle config, this will save your build options to ~/.bundle/config, so that the next time you need to build your gem, the configuration options will already be set, eg:

如果您使用的是bundler,您可以使用为您的 gem 设置构建参数bundle config,这会将您的构建选项保存到~/.bundle/config,以便下次您需要构建您的 gem 时,配置选项将已经设置,例如:

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

bundle config man page

捆绑配置手册页

回答by ctcherry

If you are willing, you can try a completely different approach using homebrew to install mysql:

如果你愿意,你可以尝试一种完全不同的方法,使用 homebrew 来安装 mysql:

https://github.com/mxcl/homebrew

https://github.com/mxcl/homebrew

And then try installing the gem based on that.

然后尝试在此基础上安装 gem。

回答by abmap

For mac as of November 2018

截至 2018 年 11 月的 Mac

gem install mysql2 -v '0.4.8' -- --with-ldflags=-L/usr/local/opt/[email protected]/lib --with-cppflags=-I/usr/local/opt/[email protected]/include