Cannot install mysql2 gem

前端 未结 9 2342
死守一世寂寞
死守一世寂寞 2020-12-05 01:20

I\'m unable to install the mysql2 gem in my Windows7 x64 system. I tried using both the 32-bit and 64-bit versions of MySQL server but none got me any further.

I ins

相关标签:
9条回答
  • 2020-12-05 01:24

    Here's what worked for me using: Win7 64/MySQL 5.5 64-bit/Ruby 1.9.2:

    1. Download libmysql.dll.
    2. Copy the above libmysql.dll to C:\Ruby192\bin AND C:\Ruby192\lib, or wherever your lib and bin are.
    3. Run:
    gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.5"'
    

    Good luck.

    0 讨论(0)
  • 2020-12-05 01:25

    Copy the libmysql.dll located in the bin directory of your MySQL install to the bin directory of your Ruby install. Mine were located in C:\Program Files\MySQL and C:\Ruby.

    0 讨论(0)
  • 2020-12-05 01:26

    I had similar problems with MySQL 5.6 under 64-bit Windows 7. The main solution given here worked. (the solution suggested by kobalz of just copying the dll didn't work. No idea why it works for kobalz but not for me!)

    I then ran into another problem which is described in this post:

    mysql2 gem compiled for wrong mysql client library

    The solution described there avoids downloading a complete 32-bit MySQL and fixed both problems. Essentially, download the mysql connector (a much smaller download) and use that to compile the mysql2 gem. You have to download exactly the right version, as described in the post. In my case:

    http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

    then copy the lib\libmysql.dll file from there into your Ruby bin directory as described above.

    I put my connector into c:\mysql-connector-c-noinstall-6.0.2-win32

    so the command to build and install the gem was:

    gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib" --with-mysql-include="c:\mysql-connector-c-noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"

    I then ran into further problems when I ran rake to do a migration, but that was because I had been using the mysql gem (not mysql2) and I had forgotten to update my database.yml. With the mysql2 gem, it needs to say:

    development: adapter: mysql2

    rather than

    development: adapter: mysql

    which is obvious once you've figured it out, but the error messages I got were similar to the ones I got before, so it looked as if there was still something wrong with my gem.

    0 讨论(0)
  • 2020-12-05 01:26

    This one worked for me for a MariaDB 5.5 installation:

    gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mysql"'

    Building native extensions with: '--with-mysql-lib="c:\Program Files (x86)\Maria DB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mys ql"'

    Be sure to use x64 MariaDB packages if you plan to use Ruby x64. And of course, don't forget to copy C:\Program Files (x86)\MariaDB 5.5\lib\libmysql.dll to c:\Ruby200\bin in my case.

    0 讨论(0)
  • 2020-12-05 01:28

    I finally solved it:

    1. Downloaded and installed MySQL 64bit version 5.5
    2. Downloaded the zip archive for the 32bit version 5.5.
    3. Extracted the 32-bit include and lib folders to C:\MySQL.
    4. Installed Ruby 1.9.2.
    5. Installed the Ruby Devkit.
    6. Installed the gems:
      1. gem install mysql
      2. gem install mysql2 -- --with-mysql-lib=C:\MySQL\lib --with-mysql-include=C:\MySQL\include
      3. gem install rails
      4. gem install fastthread
      5. gem install haml

    It's working as a charm now. It seems the MySQL gem has issues finding the data when dealing with 64-bit.

    0 讨论(0)
  • 2020-12-05 01:33

    I know the thread is related to Windows but I reached it searching for the same issue on Linux and I fixed it by installing the lib "libmysqlclient-dev"

    0 讨论(0)
提交回复
热议问题