Tan*_*ner 71 ruby mysql rubygems libmysql mysql2
当我尝试安装mysql2 gem时,它失败并没有明显的错误.有谁知道如何解决这个问题,所以mysql2安装?
$ sudo gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
小智 145
Ubuntu的:
sudo apt-get install libmysqlclient-dev  #(mysql development headers)
sudo gem install mysql2 -- --with-mysql-dir=/etc/mysql/
而已!
结果:
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known
Hol*_*ust 41
您需要mysql2的MySQL开发头才能正确编译.这是必需的,因为大部分功能都是用C语言编写的,后来又链接到MySQL.
解决方案是将gem安装程序明确指向mysql安装文件夹
gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
# or where ever you installed your mysql server to
或者通过将mysql服务器安装到已知位置(例如使用自制软件),然后安装gem
# install the mysql server locally
brew install mysql
# install the gem
gem install mysql2
这两种方法都要求您安装XCode以具有所需的GCC编译器.
cor*_*ard 27
您必须在计算机上安装64位MySQL,以及安装xcode时获得的构建工具.
dka*_*kam 22
安装Brew和MySQL后,我使用以下命令安装mysql2 gem
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.10/bin/mysql_config
如果你正在使用Bundler,你可以通过命令告诉bundler:
bundle config build.mysql2 --with-mysql-config=/usr/local//Cellar/mysql/5.5.10/bin/mysql_config
如此处所述:http://gembundler.com/man/bundle-config.1.html
在Mac OSX Moutain Lion上,下面的命令对我有用:
gem install mysql2 -- --srcdir=/usr/local/mysql/include
Ubuntu 15.04:
sudo apt-get install libmysqlclient-dev
sudo gem install mysql2
Ubuntu的16.04:
sudo apt-get install ruby-mysql2
sudo gem install mysql2
输出:
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.19
Parsing documentation for mysql2-0.3.19
Installing ri documentation for mysql2-0.3.19
Done installing documentation for mysql2 after 0 seconds
1 gem installed