一、下载安装mysql
二、安装mysql2
在windows 安装
gem install mysql2 -- \ --with-mysql-dir=D:\mysql
在linux下安装
gem install mysql2 -- \ --with-mysql-lib=/var/lib/mysql -- \ --with-mysql-include=/usr/include/mysql
错误报告:
This could take a while...
ERROR: Error installing mysql2: ERROR: Failed to build gem native extension./usr/local/ruby/bin/ruby extconf.rb --with-mysql-dir=/var/lib/mysql -- --with-mysql-include=/usr/include/mysql
checking for ruby/thread.h... yeschecking for rb_thread_call_without_gvl() in ruby/thread.h... yeschecking for rb_thread_blocking_region()... yeschecking for rb_wait_for_single_fd()... yeschecking for rb_hash_dup()... yeschecking for rb_intern3()... yes-----Cannot find include dir at /usr/include/mysql:/usr/include/mysql:/var/lib/mysql/include-----*** extconf.rb failed ***Could not create Makefile due to some reason, probably lack of necessarylibraries and/or headers. Check the mkmf.log file for more details. You mayneed 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=/usr/local/ruby/bin/ruby --with-mysql-dir --with-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/libextconf failed, exit code 1
Gem files will remain installed in /usr/local/ruby/lib/ruby/gems/2.1.0/gems/mysql2-0.3.15 for inspection.
Results logged to /usr/local/ruby/lib/ruby/gems/2.1.0/extensions/x86-linux/2.1.0-static/mysql2-0.3.15/gem_make.out
因为确实mysql头文件, 先确认是否安装了mysql-devel,安装后,看是否指定了头文件的目录。
注意:务必安装 mysql-devel包