brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.24k stars 546 forks source link

MySQL 8.0.34 and 8.1.0 deprecates `MYSQL_OPT_RECONNECT` #1322

Open yahonda opened 11 months ago

yahonda commented 11 months ago

MySQL 8.0.34 and 8.1.0 deprecates MYSQL_OPT_RECONNECT

Since MySQL 8.0.34 and 8.1.0 deprecates MYSQL_OPT_RECONNECT, mysql2 gem is also affected.

https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-34.html#mysqld-8-0-34-deprecation-removal https://dev.mysql.com/doc/relnotes/mysql/8.1/en/news-8-1-0.html#mysqld-8-1-0-deprecation-removal

The MySQL client library currently supports performing an automatic reconnection to the server if it finds that the connection is down and an application attempts to send a statement to the server to be executed. Now, this feature is deprecated and subject to removal in a future release of MySQL.

The related MYSQL_OPT_RECONNECT option is still available but it is also deprecated. C API functions mysql_get_option() and mysql_options() now write a deprecation warning to the standard error output when an application specifies MYSQL_OPT_RECONNECT. (WL #15766)

Here are two specs that raise WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.

$ bundle exec rspec spec/mysql2/client_spec.rb -e "should send init_command after reconnect"
<internal:gc>:251: warning: double_heap is deprecated, please use expand_heap instead
Run options: include {:full_description=>/should\ send\ init_command\ after\ reconnect/}

Randomized with seed 13185

Mysql2::Client
WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.
  should send init_command after reconnect

Finished in 0.01231 seconds (files took 0.11187 seconds to load)
1 example, 0 failures

Randomized with seed 13185

$
$ bundle exec rspec spec/mysql2/client_spec.rb -e "should not try to query closed mysql connection"
<internal:gc>:251: warning: double_heap is deprecated, please use expand_heap instead
Run options: include {:full_description=>/should\ not\ try\ to\ query\ closed\ mysql\ connection/}

Randomized with seed 29247

Mysql2::Client
WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.
  should not try to query closed mysql connection

Finished in 0.00981 seconds (files took 0.11158 seconds to load)
1 example, 0 failures

Randomized with seed 29247

$

* Installed packages

$ sudo apt list --installed |grep mysql ... snip ... libmysqlclient-dev/now 8.1.0-1ubuntu23.04 amd64 [installed,local] libmysqlclient22/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-apt-config/now 0.8.24-1 all [installed,local] mysql-client/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-common/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-community-client-core/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-community-client-plugins/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-community-client/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-community-server-core/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-community-server/now 8.1.0-1ubuntu23.04 amd64 [installed,local] mysql-server/now 8.1.0-1ubuntu23.04 amd64 [installed,local] $

sodabrew commented 11 months ago

It's pretty exciting to see the news on MySQL 8.x Innovation releases breathing some life into it.

If a user wants to put in a deprecated option they may do so. I wouldn't remove the flag bindings yet, but would certainly want to gracefully handle the missing definition in future versions of the mysql2 gem.

jamgregory commented 10 months ago

Just wanted to add to this: passing in reconnect as a config option, regardless of whether it is true or false (or even nil) will cause this error to be displayed (just spotted this in our Rails app as it has reconnect: false configured in database.yml)

I guess ideally it should not even set this if reconnect: false as that's the default (according to https://dev.mysql.com/doc/c-api/8.0/en/c-api-auto-reconnect.html, anyway) but it would be good if a clearer deprecation message could be displayed by the gem :+1:

pioz commented 10 months ago

Same warning here with MySQL 8.1 and mysql2 0.5.5.

alvincrespo commented 9 months ago

Does anyone know why MYSQL_OPT_RECONNECT is being deprecated? I tried looking for the related work log item, 15766, but couldn't find it here.

ahmetabdi commented 9 months ago

Any updates on this? will this not break mysql2 once MYSQL_OPT_RECONNECT is removed?

sodabrew commented 9 months ago

It will break when removed, yes. Need to get in a conditional definition with an in-Ruby warning that says the feature was removed.

ram-gudapati commented 7 months ago

@sodabrew our c++ application uses mysql_options with MYSQL_OPT_RECONNECT. what are alternatives so we get the same behavior without changing our application code to get same behavior as RECONNECT. if changing the application is only option what is the best way with minimal impact, so the reconnect works as before.

breisig commented 4 months ago

It would be nice to get rid of this MYSQL_OPT_RECONNECT warning message.

joshuapinter commented 4 months ago

@breisig FYI, we moved to Trilogy. Would highly recommend it as well, if it's possible for you. Modern and well-maintained going forward. Some tweaks needed but mostly a drop-in replacement.

breisig commented 4 months ago

@joshuapinter Trilogy doesn't have basic caching_sha2_password support which is required in newer MySQL 8.x so that's out.

gdubicki commented 1 month ago

@joshuapinter Trilogy doesn't have basic caching_sha2_password support which is required in newer MySQL 8.x so that's out.

The support for that has been added recently - see https://github.com/trilogy-libraries/trilogy/releases/tag/v2.8.0, @breisig. I haven't yet used Trilogy myself, but github.com stands behind it, so it looks solid.