mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

Incorrect MySQL client library version! This gem was compiled for 10.8.8 but the client library is 3.4.3. (Ruby on Rails - MySQL)

Open PAWANRAJ-CSE opened this issue 11 months ago • 4 comments

Hi all!

Check this info:

ruby -v ruby 3.3.7 (2025-01-15 revision be31f993d7) [x64-mingw-ucrt]

rails -v Rails 8.0.1

bundle info mysql2

mysql2 (0.5.6) Summary: A simple, fast Mysql library for Ruby, binding to libmysql Homepage: https://github.com/brianmario/mysql2 Documentation: https://www.rubydoc.info/gems/mysql2/0.5.6 Source Code: https://github.com/brianmario/mysql2/tree/0.5.6 Changelog: https://github.com/brianmario/mysql2/releases/tag/0.5.6 Bug Tracker: https://github.com/brianmario/mysql2/issues Path: C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/mysql2-0.5.6 mysql -V mysql Ver 8.0.40 for Win64 on x86_64 (MySQL Community Server - GPL)

The error is as follows:

Caused by: Incorrect MySQL client library version! This gem was compiled for 10.8.8 but the client library is 3.4.3. internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb:37:in require' internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb:37:in require' F:/CSE/ROR-2024/PROJECTS/ONE/thirdapp/config/application.rb:7:in

' F:/CSE/ROR-2024/PROJECTS/ONE/thirdapp/Rakefile:4:in require_relative' F:/CSE/ROR-2024/PROJECTS/ONE/thirdapp/Rakefile:4:in
' bin/rails:4:in

' (See full trace by running task with --trace) How to resolve the issue?? Kindly help

PAWANRAJ-CSE avatar Feb 06 '25 09:02 PAWANRAJ-CSE

Edit C:\Ruby33-x64\msys64\ucrt64\include\mysql\mariadb_version.h change to #define MARIADB_CLIENT_VERSION_STR "3.4.3"

msg7086 avatar Feb 20 '25 09:02 msg7086

Referring to #1348 (comment) and #1210 (comment), you can try the following steps:

Uninstall mysql2: gem uninstall mysql2 Clone the mysql2 repository: git clone https://github.com/brianmario/mysql2.git Enter the mysql2 directory: cd mysql2 Switch to tag v0.5.6: git checkout 0.5.6 Edit the client.c file: notepad ext\mysql2\client.c #(and comment out line 1541-1543) Return to the mysql2 directory: cd ..\.. Edit the mysql2 version information: notepad lib\mysql2\version.rb #(and change the version to 0.5.6.1) Build the gem: gem build mysql2.gemspec Copy the resulting mysql2-0.5.6.1.gem file to your project folder Delete the Gemfile.lock file Modify the Gemfile to change the mysql2 version: gem "mysql2", "~> 0.5.6.1" Execute bundle.bat in your project Verify that the version information is 0.5.6.1 by running the command: gem info mysql2

FenleyHalebourne avatar Mar 12 '25 10:03 FenleyHalebourne

Edit C:\Ruby33-x64\msys64\ucrt64\include\mysql\mariadb_version.h change to #define MARIADB_CLIENT_VERSION_STR "3.4.3"

Uninstall mysql2: gem uninstall mysql2 Reinstall mysql2: bundle install

BenyLaLa avatar Apr 07 '25 11:04 BenyLaLa

any update on this? having the same issue.

aunghtain avatar May 29 '25 17:05 aunghtain

ruby 3.3 and 3.4, having the same issue.

songgz avatar Jun 07 '25 01:06 songgz

This error is caused by different MySQL or MariaDB client libraries in the compile environment vs. runtime environment. It is not affected by the Ruby version.

sodabrew avatar Jun 07 '25 02:06 sodabrew

Edit C:\Ruby33-x64\msys64\ucrt64\include\mysql\mariadb_version.h change to #define MARIADB_CLIENT_VERSION_STR "3.4.3"

Uninstall mysql2: gem uninstall mysql2 Reinstall mysql2: bundle install

This works, but is only a temporary solution.

mzdz avatar Jun 08 '25 01:06 mzdz

been through this in older version of gem. just clone, modify and build the gem basefile like mine https://github.com/nandangpk/techno-gems/tree/debian-12/mysql2/0.3.21

nandangpk avatar Jul 02 '25 18:07 nandangpk

The MYSQL_LINK_VERSION compiled into the gem is from MARIADB_CLIENT_VERSION_STR

https://github.com/brianmario/mysql2/blob/master/ext/mysql2/client.c#L53

Depending on if this is compiled with a server this will have a server version or a 10.8.8 (magic?) version

https://github.com/mariadb-corporation/mariadb-connector-c/blob/cacd251e204b9bafb7ec27adc739f98e7ca4fe86/CMakeLists.txt#L179

The runtime check of mysql2 uses mysql_get_client_info

https://github.com/brianmario/mysql2/blob/441b104f8f120788e86086702d96963aecec3172/ext/mysql2/client.c#L1550

The MariaDB implementation of mysql_get_client_info is:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/cacd251e204b9bafb7ec27adc739f98e7ca4fe86/libmariadb/mariadb_lib.c#L3446

So it uses the MARIADB_PACKAGE_VERSION

As such mysql2 shouldn't be using MARIADB_CLIENT_VERSION_STR, it needs the package version

https://github.com/mariadb-corporation/mariadb-connector-c/blob/cacd251e204b9bafb7ec27adc739f98e7ca4fe86/CMakeLists.txt#L53-L56

exposed as the define MARIADB_PACKAGE_VERSION, same as mysql_get_client_info:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/cacd251e204b9bafb7ec27adc739f98e7ca4fe86/include/mariadb_version.h.in#L29

grooverdan avatar Jul 16 '25 04:07 grooverdan