Open SuperSajuuk opened 3 years ago
For anyone who is interested, i was able to get this to install from the rubygems.org directly after passing the path to the c bindings but this won’t install via bundler specifying a git url with this error. I can’t tell if the rubygems site matches the github repo but seems to work now,
Hi, Try with this https://medium.com/ruby-on-rails-web-application-development/installing-the-mysql2-rubyonrails-gem-on-windows-7-8-a028f44d87f3
Hi yeah I found that guide but it wasn't working in Bundler as it refused to take the arguments from the .bundle file. Worked fine installing directly outside of Bundler though, which I was able to do. 👍
I got this exact same error in the same line 1771. After an entire day of trial and error, I found that I could install a working mysql2
gem on Ruby 2.7.3 on Windows 10 (working: at least for basic queries).
cmd
terminal and run ridk
explicitely (c:\your\path\to\Ruby27-x64\ridk.cmd enable
). This gives you the right environment to do the rest.cmd
, run gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your/path/to/Ruby27-x64/msys64/mingw64
(no particular quote was neeeded and I used forward slashes. This was adapted from this answer )FWIW, I could get a non functional gem to build with the C Connector 6.1.11 by doing so:
c:\your\path\to\mysql-connector-c-6.1.11-winx64
(no spaces. May or may not be important)cmd
terminal and run ridk
explicitely as step 1 above.cmd
, run gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your/path/to/mysql-connector-c-6.1.11-winx64
(no particular quote was needed and I used forward slashes)require 'mysql2'
is executed: Incorrect MySQL client library version! This gem was compiled for 6.1.11 but the client library is 10.5.5. (RuntimeError)
. I believe this is because MariaDB stuff gets linked to the resulting mysql2.so
no matter what (it gets forcibly installed too if missing). I have not found how to link the DLL shipped with the C connector. (I tried various --with-xxxx
switches without success)Also note that I tried to build with gem install mysql2 --platform=ruby -- --use-system-libraries
as suggested in the article linked above. That ended up with a different build failure (in line 1050 ofmkmf.rb
rather than 1771).
I have also noticed to that a consistent predictor of a failed build is the second line that starts with
Building native extensions with:
. When the subsequent text --with-xxxx
is followed by an equal sign then the build succeed. When it is followed by a space, the build fails. I suspect there are some quoting and/or parsing issues somewhere (maybe paths containing spaces are part of the problem ?)
Hope this helps
@pcopissa's solution put me on the right track, except I wanted to use the MariaDB library.
libmariadb
folder to lib
cmd
terminal and run ridk
gem install mysql2 --platform=ruby -- --with-mysql-dir=C:/Users/clark/Downloads/mariadb-connector-c-3.1.13-src
(or wherever your unzip'd it)The gem compiled, although I haven't tested it yet, so I have yet to see if it works ¯\_(ツ)_/¯
I was able to get this working on OSX by (note this assumes Homebrew is installed):
gem uninstall mysql2
brew uninstall mariadb
brew install mariadb
gem install mysql2 --platform=ruby -- --with-mysql-dir=/usr/local/Cellar/mariadb/10.8.3_1
bundle install
in your Rails projectNote that I happened to do the uninstall/reinstall of mariadb but a brew upgrade
might be enough.
I'm also not sure if there's a better way to specify the 'mysql_dir' when in installing the gem. Brew creates symlinks to the executables but I didn't find any links to the root 'Cellar/mariadb/[version]' dir. I suppose one could be added manually (and updated as needed).
cmd
terminal and run ridk
gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your/path/to/Ruby27-x64/msys64/mingw64
Thank you @pcopissa
Only these Two commands works for me.
1. Start `cmd` terminal and run `ridk` 2. From that cmd, run `gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your/path/to/Ruby27-x64/msys64/mingw64` * Make sure that you specify the right path to Ruby installed in your computer
Thank you @pcopissa
Same for me on W2016 with Ruby v2.7.7
Only these Two commands works for me.
- Start
cmd
terminal and runridk
From that cmd, run
gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/your/path/to/Ruby27-x64/msys64/mingw64
- Make sure that you specify the right path to Ruby installed in your computer
Thank you @pcopissa
Thanks @pcopissa I tried many other methods over the last 2 days. This is what worked for me
Open cmd
C:\Windows\System32>ridk
large printout of Ruby Installer 2 for Windows
C:\Windows\System32>gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/Ruby32/msys32/mingw32
Temporarily enhancing PATH for MSYS/MINGW... Using msys2 packages: mingw-w64-i686-libmariadbclient Building native extensions with: '--with-mysql-dir=c:/Ruby32/msys32/mingw32' This could take a while... Successfully installed mysql2-0.5.5 Parsing documentation for mysql2-0.5.5 Installing ri documentation for mysql2-0.5.5 Done installing documentation for mysql2 after 2 seconds 1 gem installed
Nearly fell off my chair when it worked. Please note that DevKit needs to be down loaded and need to ensure that all 3 options are installed
C:\Windows\System32>gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/Ruby32/msys32/mingw32
This works but does anybody know why? Pointing the mysql dir to Ruby dir is the lasts thing I would have thought would work. Am I misinterpreting what that flag is for? I thought it was the pat to MySQL
Start cmd terminal and run ridk
From that cmd, run gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/Ruby32-x64/msys64/mingw64 Thanks a lot! These cmd lines did help me solve the problem, I'm using Windows 11
@pcopissa Thanks a lot. it works for me having windows-10 and ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
Start cmd terminal and run ridk
From that cmd, run gem install mysql2 --platform=ruby -- --with-mysql-dir=c:/Ruby32-x64/msys64/mingw64 Thanks a lot! These cmd lines did help me solve the problem, I'm using Windows 11
work using this command on windows 11 and ruby 3.1.4. thanks
@gersonmax:
This works but does anybody know why? Pointing the mysql dir to Ruby dir is the lasts thing I would have thought would work. Am I misinterpreting what that flag is for? I thought it was the pat to MySQL
The answer is twofold, I think:
First, MSYS2 does not have a MySQL package, but a MariaDB one and they are sufficiently similar header-wise and symbol-wise (I assume that's deliberate ?) that you can use use MariaDB's stuff instead of MySQL's. Hence I just installed the MariaDB package for MSYS2 (that ends up in the standard folders under Unix /
).
Second, I believe --with-mysql-dir
points where the installer will pick source files from (i.e. headers and shared libraries/DLL), expecting the classic Unix hierarchy starting at /
(ie: /lib
and /include
mostly). Since we are executing the build with a Unix-ish toolchain but in a cmd
prompt, we have to specify a place that looks like Unix /
. Indeed, if you look at bullet 4 of my post, you will see that it did manage to build a gem, although a non functional one, using the path to the source for the MySQL connector. And that connector's folder is indeed structured as Unix /
.
Putting those two considerations together, you end up passing in --with-mysql-dir
the place which MSYS2 considers as /
and that is c:/your/path/to/Ruby27-x64/msys64/mingw64
when using Ruby 2.7.x (or c:/your/path/to/Ruby32-x64/msys64/ucrt64
for Ruby 3.2.x since you asked...). Other posts above used other paths possibly because they had a 32-bit Ruby which relies on MSYS2 having its /
in yet some other place.
I tried my best to contact MySQL devs to support MINGW package, yet done it: https://github.com/msys2/MINGW-packages/pull/16085
I've just managed to install mysql2-0.5.6
on Windows 10 with Ruby 3.2.3
this way:
gem install mysql2 --platform=ruby -- --with-mysql-lib="C:\MySQL\MySQL Connector C++ 8.3\lib64"
Thanks, it works for me
Hi there. I'm trying to install this gem into my Ruby installation (Ruby 2.7.4, via msys2, x64-mingw32: Windows 10 v2004) but no matter what I attempt to do, I get this error consistently:
Any ideas on how to fix, or is the latest gem version non functional at the moment? I've confirmed that I have the required system libraries present and I've even tried, as per the error message, to point the gem to use the locally installed MariaDB 10.4, but nothing works. Help would be appreciated.