mysql2
mysql2 copied to clipboard
MySQL 8.0.34 and 8.1.0 deprecates `MYSQL_OPT_RECONNECT`
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
$
- Ruby and MySQL version
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ mysql -uroot -e 'select version()'
+-----------+
| version() |
+-----------+
| 8.1.0 |
+-----------+
$
- 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]
$
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.
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:
Same warning here with MySQL 8.1 and mysql2 0.5.5.
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.
Any updates on this? will this not break mysql2 once MYSQL_OPT_RECONNECT is removed?
It will break when removed, yes. Need to get in a conditional definition with an in-Ruby warning that says the feature was removed.
@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.
It would be nice to get rid of this MYSQL_OPT_RECONNECT warning message.
@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.
@joshuapinter Trilogy doesn't have basic caching_sha2_password support which is required in newer MySQL 8.x so that's out.
@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.