I spent almost an entire evening to find out why I couldn’t install the mysql2 gem on my windows 8.1. Don’t know if it’s easier with previous windows but I’ll show you how I did it.
A bundle install gave me this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
Installing mysql2 (0.3.14) Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. C:/Ruby200/bin/ruby.exe 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 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... no 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=C:/Ruby200/bin/ruby --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/ --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}/ --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 C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14 for inspection. Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/ext/mysql2/gem_make.out An error occurred while installing mysql2 (0.3.14), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.14'` succeeds before bundling. |
First, you need to install mysql libraries packaged with mysql-server installer. You’ll need them to compile the gem afterwards. Choose the mysql version 32bits or 64-bits depending on what you version of ruby you installed for a better compatibility. 32bits version of mysql is in Program Files (x86). if you choose 64bits version, mysql is in Program Files.
I installed mysql 5.5 32bits, download is here Windows (x86, 32-bit), MSI Installer. I configured and checked the Add Mysql Bin Folder to PATH box.
Now you’re going to install the gem in a command window and type:
1 2 3 4 5 6 7 8 9 10 |
gem install mysql2 -- '--with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib" --with-mysql-include="C:\Program Files (x86)\MySQL\MySQL Server 5.5\include"' Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib" --with-mysql-include="C:\Program Files (x86)\MySQL\MySQLServer 5.5\include"' This could take a while... Successfully installed mysql2-0.3.14 Parsing documentation for mysql2-0.3.14 Installing ri documentation for mysql2-0.3.14 Done installing documentation for mysql2 after 0 seconds 1 gem installed |
Then copy the libmysql.dll found in C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib to your ruby bin folder C:\Ruby200\bin
For your information, here is a short example of mysql2 database implementation in config/database.yml :
1 2 3 4 5 6 7 8 |
production: adapter: mysql2 encoding: utf8 database: mydb username: user password: pass host: 127.0.0.1 port: 3306 |
To learn how to deal with ActiveRecord and MySQL: Active Record Query Interface Tutorial
Recent Comments