Skip to content

'Mysql2::Client#connect': TLS/SSL error: SSL is required, but the server does not support it (Mysql2::Error::ConnectionError) #1395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AndreaLai74 opened this issue Mar 7, 2025 · 2 comments

Comments

@AndreaLai74
Copy link

AndreaLai74 commented Mar 7, 2025

I have this error where run my program on Windows x64 Operating Sistem.

First of all in the file "c:\ruby34-x64\msys64\ucrt64\include\mysql\mariadb_version.h" I have change this line " #define MARIADB_CLIENT_VERSION_STR "3.4.3" "

Because otherwise an error appears about the match of the database version.

Also in then "mysql2\ext\mysql2\client.c" I have commented this lines

    /*
    if (lib[i] != MYSQL_LINK_VERSION[i]) {
      rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_LINK_VERSION, lib);
    }*/

Make that I have install mysql2 with this command:

gem build .\mysql2.gemspec
gem install .\mysql2-0.5.6.gem -- --with-mysql-dir=d:/ruby_pgm/mariadb-connector-c

The library is install correctly but the error in the object appears when run my program.

Can anyone help me ?

@nonnenmacher
Copy link

got perhaps the same problem but on Mac (could the same underlying cause).

Got the same Error message for connection.

  1. on using ruby through asdf everything works fine (without the need to specify anything like ssl_mode = 'disabled')
  2. using mise (tested on [email protected] and [email protected] and get this error (tried all variations of 'disabling ssl`

Culprit seems to be around CFLAGS and CPPFLAGS compilation settings.

on asdf compiled mysql2 gem in the gem directory Makefile I see

CPPFLAGS = -DHAVE_RB_ABSINT_SIZE ....  -DHAVE_CONST_SSL_MODE_DISABLED -DHAVE_CONST_SSL_MODE_PREFERRED -DHAVE_CONST_SSL_MODE_REQUIRED -DHAVE_CONST_SSL_MODE_VERIFY_CA -DHAVE_CONST_SSL_MODE_VERIFY_IDENTITY ... -DHAVE_MYSQL_SSL_SET ...

on mise compiled gem the Makefile reads as follows

CPPFLAGS = -DHAVE_RB_ABSINT_SIZE ... -DHAVE_CONST_MYSQL_OPT_SSL_VERIFY_SERVER_CERT -DHAVE_CONST_MYSQL_OPT_SSL_ENFORCE ...  -DHAVE_MYSQL_SSL_SET...

The culprit seems to be the setting of this DHAVE_CONST_MYSQL_OPT_SSL_ENFORCE flag.

when looking at code, this flag set some C macros around.

#ifdef HAVE_CONST_MYSQL_OPT_SSL_ENFORCE
  #define SSL_MODE_DISABLED 1
  #define SSL_MODE_REQUIRED 3
  #define HAVE_CONST_SSL_MODE_DISABLED
  #define HAVE_CONST_SSL_MODE_REQUIRED
#endif

which indeed affects client.c behaviour

haven't yet found a way to compile gem for NOT settings this C flags HAVE_CONST_MYSQL_OPT_SSL_ENFORCE

at the bundle config level.

@nonnenmacher
Copy link

oops digging deeper, I found where could be the source of this MYSQL_OPT_SSL_ENFORCE flags.
It turns out that on my mysql2 gem native installation between installation using asdf or mise

  1. asdf included standard Mysql headers
  2. mise use MariaDB equivalent of mysql.h

And in the MariaDB install there is a declaration of this options

enum mysql_option 
  {
      ....
     MYSQL_OPT_SSL_ENFORCE,
    ...
 }

Which doesn't exist in the standard mysql-client one.

So the extconf.rb do not generate the same Makefile ;-(

Perhaps you should check your generated Makefile on your gems folder to see if you are in a similar situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants