Ruby Install Mysql2 Gem Windows

Ruby Install Mysql2 Gem Windows Average ratng: 4,6/5 6268 votes

If you cannot install the MYSQL2 gem in Windows, you need to download the C-Header files from MYSQL. Unlike other gems, MYSQL2 requires direct linking into some of the native build files provided by the library. Unless you have MYSQL installed already, it means you need to download – and reference – this library from the Internet. The problem is that since the MYSQL2 gem requires certain files to help it connect to the Internet, the gem uses these to at build. The error you’ll receive will mention “Failed to build native extensions”. This means your Windows system did not have the header files required for the gem to be installed correctly. The way to resolve this is to first log onto the MYSQL website and look for “C-Connector”.

  1. Ruby Install Mysql2 Gem Windows

This is basically the “driver” for MYSQL, allowing Windows to call a number of pre-compiled functions to help it communicate with local or external MYSQL installations. The purpose of this download is to ensure your computer has the necessary files to install the gem. Once you have found the MYSQL C-Connector file, you need to download it to your hard drive. From this, unzip the file and place its contents on your hard drive.

You must put it in a path which has no spaces, otherwise the installation reference will break. Paul simon hearts and bones rar. A path such as C:/downloads/mysql-c-connector/files will work fine. Please note you do NOT need to install this – only download the zipped archive, we can remove it after the gem has been installed.

If you have downloaded and placed the files on your hard drive, you need to then install the gem again. To do this, you should load up CMD and type the following command “gem install mysql2 –platform=ruby — ‘–with-mysql-dir=”C:mysql-connector-path”‘”. This command will reference the newly installed MYSQL C-Connector library files which Ruby requires to build the gem.

If you’ve downloaded / installed it correctly, this should allow Ruby to install the required files etc. If successful, the cmd will explain the gem has been installed; if not, it will likely be that you have either downloaded the incorrect files OR you have not got another necessary library installed on your system. Since Windows comes with no external libraries, it’s necessary to install any required from the Internet.

This is one of the reasons most people don’t like developing with Windows – ultimately, if you’re able to download the correct header files, you should be fine.

As it indicates, check out: Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2‌​/g emmake.out and also mkmf.log for descriptive errors. Post them here. It probably needs headers such as by supplying 'gem install mysql2 - -with-MySQL-lib='. These files can be downloaded to permit installation, but make sure it matches your gem's mod level. I use BitNami Rubystack on Windows 8 which includes MySQL. RailsInstaller is a very popular comprehensive install.

– Sep 26 '13 at 4:11. EDIT When this answer was posted the 64 bit rails installer wasn't the recommended version - it now seems people are starting to use it more. It should be noted when you download the MySQL Connector you need to download either 64 or 32bit to correspond to the version of rails you installed. Amazingly I lucked upon an answer very early this morning as I happened to be looking for something else of a similar nature. I'm not quite sure why there isn't a single simple guide for this as it appears to be very straight forward!

Ruby Install Mysql2 Gem Windows

For some reason just specifying the mysql-dir when you install the gem doesn't pick up with other sub directories so you need to set the parameters manually. For anyone else experiencing the same problem, I did the following: 1) Download the MySql C Connector from: NOTE Don't download the installer, download the ARCHIVE for your OS Download either the 32bit or 64 bit ARCHIVE to correspond with the version of rails you installed. 2) Extract the file to C: mysql-connector 3) Then ran: gem install mysql2 -platform=ruby - '-with-mysql-lib='C: mysql-connector lib' -with-mysql-include='C: mysql-connector include' -with-mysql-dir='C: mysql-connector' Voila everything is working fine. EDIT I just had to do a fresh install on a bricked machine and the command in step 3 didn't work, what did work was: gem install mysql2 -platform=ruby - '-with-mysql-dir='C: mysql-connector' I'm not quite sure what the difference is but this time it seems to be picking up the directories ok, so if the first one doesn't work try this one! I think this has to do with how you go about installing rails, this time round I used the railsinstaller which seems to set the paths up correctly. A lot of the outcome here seems to depend on the shell your using, a lot of people are having problems with powershell so I wouldn't advise using it.

I did this in an elevated command prompt. Oh and lastly if you get an error regarding the mysql2 gem when you do RAILS S you need to copy the libmysql.dll from the LIB directory of the mysql connector to the bin directory where rails has been installed. I've tried the solution of @Mrk Fldig but it didn't work. So what solved the problem was:. Downloaded the lastest MySQL for windows 7 32 bits. Installed the gem with the following command: gem install mysql2 -platform=ruby - '-with-mysql-dir='C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/' One pitfall to be aware of is that I changed the backslashes ( ) to normal slashes (/). I've tried the same procedure with backslashes and it didn't work.

The installer already includes the C connectors for MySQL at MySQL Connector C 6.1 6.1.2 directory. Therefore, passing only the -with-mysql-dir parameter without the -with-mysql-lib or -with-mysql-include parameters, makes the gem to look at the same directory for the lib and include directories.

For Cygwin, I could consolidate various steps. Use cygwin setup.exe to download gcc, g, make, cmake and libmysqlclient-devel (from cygwin ports). Download c/connector src for windows from mysql site.

I downloaded 6.x version. OR download libmysqlclient-devel's version (not sure from where).

Windows

unzip. cd dirconnector. Not required and RISKY, but if cygwin libmysqlclient-devel version is 5.5.40, then change dirconnector/VERSION file's versions to 5.5.40. mkdir build. cd build. comment dtoa in stdlib.h, else compilation is failing. cmake.

make. make install. gem install mysql2 - -with-mysql-config=/usr/local/mysql/bin/mysqlconfig.

I downloaded the devkit 32-bit, with my 64-bit pc, however I realize that railsinstaller apparently installs a 32-bit version by default, so I have directed all facilities 32bit. Initialize the ruby devkit dk.rb init Download the mysql connector 32-bit, and place it in the mysql-connector C: mysql-connector You should be aware, that when you unzip the file, it creates a subfolder with the same name and can give errors. Then use the second command listed above: gem install mysql2 - platform = ruby - '- with-mysql-dir = 'C: mysql-connector' This was the solution I found, as I had the same problem. On Windows 7 I found that the existing answers provided a partial solution, but I still couldn't get it to install.

The problem I had was that the MySQL Community Edition Windows installer I used insisted on putting the connectors in folders called things like C: MySQL MySQL Connector C 6.1.3. The build process in the gem was reporting that it could not find 'C: MySQL MySQL' ( and before that when I had it in Program Files, it complained it couldn't find 'C: Program includes' ) so clearly the spaces were a problem and I couldn't find a way to escape them that it could understand- possibly someone will be able to suggest one of those. Because I wasn't sure whether changing these would break the installation, once I realised why the problem was arising I just created a symlink from the command line ( something that is easier from cmd than powershell ) like this: C: MySQL mklink /D ConnectorC '. MySQL Connector C 6.1.3' Then I could use the following install line: gem install mysql2 -platform=ruby - '-with-mysql-dir='C:/MySQL/ConnectorC/' This worked correctly. Also, when I tried to use it, I ran into so it may be useful to be aware that moving the MySQL lib file from the C Connector lib folder could be helpful. I managed to succeed at this out of pure luck, but after an hour of hell I feel like I should share my solution, obviously very shortened but a lot of the steps I think you can figure out how to do on your own. My machine is Win 7 64bit.

I was able to install version 0.3.16. Install ruby version 2.0.0p481 (?). Devkit blah blah.

Install rails version 4.0.0. Download Mysql Connector C 64 bit zip file, put in C drive as mysqlc. Take DLL from that bin, put it in lib of ruby.

gem install mysql2 - - with-mysql-dir='C: mysqlc'.