Bug #8591

[BUG] Segmentation fault ruby 2.0.0p195 (2013-05-14) [x64-mingw32]

Added by Josef Chmel 10 months ago. Updated 4 months ago.

Status:Third Party's Issue
Target version:-
ruby -v:ruby 2.0.0p195 (2013-05-14) [x64-mingw32] Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN


rails server crashes with Segmentation fault
in pure app created with rails new .
after installing mysql2 gem like this
gem install mysql2 -v '0.3.12b6' -- --with-opt-dir="C:\work\mysqlconnectorc61"

On Windows 7 64b with ruby 2.0 64b in C:\Ruby200-x64 installed by ruby installer rubyinstaller-2.0.0-p195-x64.exe, devkit DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe and mysql connector mysql-connector-c-6.1.0-winx64.msi.

without gem 'mysql2', '~>0.3.12b6' with gem 'sqlite3' server runs fine

Ruby 2.0 crash with mysql2.txt Magnifier (52.3 KB) Josef Chmel, 07/02/2013 12:52 AM

Related issues

Duplicated by ruby-trunk - Bug #9411: Rails server not started with Ruby(ruby 2.0.0p353 (2013-1... Feedback 01/14/2014


#1 Updated by Tomoyuki Chikanaga 10 months ago

  • Status changed from Open to Third Party's Issue

It seems like a problem of mysql2.
see also https://github.com/brianmario/mysql2/issues/372

#2 Updated by Heesob Park 10 months ago

The libmysql.lib included in the MySQL Connector/C 64 bit is not compatible with the mingw64-gcc compiler.

You need to generate mingw64 compatible libmysql.lib file.

To generate libmysql.lib file, you need gendef.exe, which can obtain from mingw-w64 distribution(I got from https://structure-svm-map.googlecode.com/files/svm-map-win.zip)

In the lib folder of the mysql connector, produce libmysql.lib with the following steps.

gendef.exe libmysql.dll

dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib

And running the normal gem install command.
gem install mysql2 -v '0.3.12b6' -- --with-opt-dir="..."

In case of MySQL Connector/C 6.1, due to the version comparison routine, you cannot use mysql2 module with the following exception.
RuntimeError: Incorrect MySQL client library version! This gem was compiled for 5.7.2-m12 but the client library is 6.1.0.

You should use mysql-connector-c-6.0.2-winx64.msi in http://dev.mysql.com/downloads/connector/c/6.0.html#downloads

#3 Updated by Nikos Timiopulos 9 months ago

Hi, I can confirm phasis68's solution works. I've just came through these steps on Windows 8 (x64) with Ruby 2.0.0-p247 (x64), MySQL 5.6.13 (x86, 64-bit).

I haven't used the connector 6.0.2. At first I compiled new libmysql.lib (as described above) from the libmysql.dll provided by MySQL lib folder. Than I installed mysql2 gem like this:

gem install mysql2 -- --with-mysql-dir=D:/Programs/MySQL/MySQLServer5.6/bin --with-mysql-lib=D:/Programs/MySQL/MySQLServer5.6/lib --with-mysql-include=D:/

And finally, copy the libmysql.dll to the Ruby bin directory. It seems to work fine so far. There is only one WARNING which is showing every time when rails server starts, or rake db commands are executed, etc.:

DL is deprecated, please use Fiddle

So I wanna ask: is it problem and can it be solved?

#4 Updated by Aaron Stone 4 months ago

This is a great find! I've been wondering what on earth the problem was. (Wish I had seen this bug months ago.)

The DL warning is just a warning, it's not a problem.

The MySQL Connector/C 6.1 should work fine in mysql2 >= 0.3.12, we fixed the version check.

Is there a way we can detect the missing gendef state and instruct the user to fix their libmysql.dll? Either at compile or load time. Should this bug be reported upstream as well, so that MySQL begins building their DLLs with the right info baked in?

#5 Updated by Heesob Park 4 months ago

mysql2-0.3.14 gem still fails with version checking with Connect/C 6.1.2.

DL is deprecated, please use Fiddle
irb(main):001:0> require 'mysql2'
RuntimeError: Incorrect MySQL client library version! This gem was compiled for
6.1.2 but the client library is 6.0.0.
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/coreext/kernelrequire.rb:4
5:in require'
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:4
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb
:8:in <top (required)>'
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:1
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/coreext/kernelrequire.rb:1
10:in rescue in require'
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:3
from (irb):1
from C:/Ruby200-x64/bin/irb:12:in `'

You can detect the wrong library file in extconf.rb like this:

if RUBYPLATFORM =~ /x64-mingw32/
abort "-----\nWrong version of libmysql.lib\n-----" unless have

The main problem is that linking using an MSVC-generated x64 *.lib file is not supported on mingw-w64 complier.

It is desired that MySQL could provide two versions of libmysql.lib, the current mvsc-generated version and mingw-w64 dlltool generated version.

#6 Updated by Aaron Stone 4 months ago

Let's move the conversation to https://github.com/brianmario/mysql2/issues/469

#7 Updated by Nobuyoshi Nakada 3 months ago

  • Duplicated by Bug #9411: Rails server not started with Ruby(ruby 2.0.0p353 (2013-11-22) [x64-mingw32] with Rails 4.0.2 and MySQL Server 5.6) added

Also available in: Atom PDF