'Mysql2::Client#connect': TLS/SSL error: SSL is required, but the server does not support it (Mysql2::Error::ConnectionError)
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 ?
got perhaps the same problem but on Mac (could the same underlying cause).
Got the same Error message for connection.
- on using ruby through
asdfeverything works fine (without the need to specify anything likessl_mode = 'disabled') - 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.
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
-
asdfincluded standard Mysql headers -
miseuse MariaDB equivalent ofmysql.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.
I have this error where it connect mysql 5.6.29 on Windows x64 ruby3.4 .
We are trying to connect to a MySQL 5.6 server without SSL using the mysql2 gem, but it fails with the following error: [paste error here].
We have tried setting ssl_mode: :disabled in the connection options, but it doesn't work. We are using mysql2 version [version] and Ruby [version].
How can we establish a non-SSL connection to MySQL 5.6?
Steps to reproduce:
-
Set up a MySQL 5.6 server without SSL.
-
Attempt to connect using mysql2 with
ssl_mode: :disabled.
Expected: Successful connection.
Actual: [Error message]
I had this issue, but I managed to connect to the legacy server by following this advice:
https://github.com/brianmario/mysql2/issues/1379#issuecomment-2671004051
Basically this:
ENV['MARIADB_TLS_DISABLE_PEER_VERIFICATION'] = '1' # <== Added this line
DB = {
host: "db.example.org",
username: "user",
password: "...",
database: "...",
encoding: "utf8mb4",
ssl_mode: "DISABLED",
secure_auth: false
}
mysql = Mysql2::Client.new(DB)
The env var is definitely needed. I'm not sure if the ssl_mode and secure_auth are needed as well (I added them first, in an earlier attempt to solve this issue), but they don't seem to cause trouble for my program so I didn't feel the need to test without them at the time.