mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

MySQL 8 - caching_sha2_password issue

Open nathan341 opened this issue 3 years ago • 3 comments

MySQL server details:

  • Server version: 8.0.28-0ubuntu0.20.04.3 - (Ubuntu)
  • Protocol version: 10

App instance details:

# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
# /usr/bin/mariadb_config
Copyright 2011-2020 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: mariadb_config [OPTIONS]
Compiler: GNU 8.3.0
  --cflags        [-I/usr/include/mariadb -I/usr/include/mariadb/mysql]
  --include       [-I/usr/include/mariadb -I/usr/include/mariadb/mysql]
  --libs          [-L/usr/lib/x86_64-linux-gnu/ -lmariadb]
  --libs_r        [-L/usr/lib/x86_64-linux-gnu/ -lmariadb]
  --libs_sys      [-ldl -lm -lpthread -lgnutls]
  --version       [10.3.36]
  --cc_version    [3.1.18]
  --socket        [/var/run/mysqld/mysqld.sock]
  --port          [3306]
  --plugindir     [/usr/lib/x86_64-linux-gnu/mariadb19/plugin]
  --tlsinfo       [GnuTLS 3.6.7]
  --variable=VAR  VAR is one of:
      pkgincludedir  [/usr/include/mariadb]
      pkglibdir      [/usr/lib/x86_64-linux-gnu]
      pkgplugindir   [/usr/lib/x86_64-linux-gnu/mariadb19/plugin]
  --libmysqld-libs  [-L/usr/lib/x86_64-linux-gnu/ -lmariadbd -ldl -lm -lpthread -lgnutls]

I am able to install the mysql2 gem but when I attempt to create the database I'm getting the following error:

# bundle exec rake db:create
RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support
Couldn't create 'my_app_database' database. Please check your configuration.
rake aborted!
ActiveRecord::ConnectionNotEstablished: RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:53:in `rescue in new_client'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:43:in `new_client'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_handling.rb:280:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/mysql_database_tasks.rb:21:in `create'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:122:in `create'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:548:in `block (2 levels) in each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:545:in `each'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:545:in `block in each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:544:in `each'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:544:in `each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `load'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `kernel_load'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:478:in `exec'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:31:in `dispatch'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:25:in `start'
/usr/local/bundle/gems/bundler-2.2.32/exe/bundle:49:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-2.2.32/exe/bundle:37:in `<top (required)>'
/usr/local/bundle/bin/bundle:25:in `load'
/usr/local/bundle/bin/bundle:25:in `<main>'

Caused by:
Mysql2::Error: RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:95:in `connect'
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:95:in `initialize'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:44:in `new'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:44:in `new_client'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_handling.rb:280:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/mysql_database_tasks.rb:21:in `create'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:122:in `create'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:548:in `block (2 levels) in each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:545:in `each'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:545:in `block in each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:544:in `each'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:544:in `each_current_configuration'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.0/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `load'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `kernel_load'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:478:in `exec'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:31:in `dispatch'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/cli.rb:25:in `start'
/usr/local/bundle/gems/bundler-2.2.32/exe/bundle:49:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-2.2.32/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-2.2.32/exe/bundle:37:in `<top (required)>'
/usr/local/bundle/bin/bundle:25:in `load'
/usr/local/bundle/bin/bundle:25:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

I found this issue https://github.com/brianmario/mysql2/issues/1023 and it's similar (both are related to the caching_sha2_password plugin) but it seems to be different than what I'm facing.

Any ideas how I can configure the gem to be able to use the correct encryption when connecting to the MySQL db?

nathan341 avatar Dec 01 '22 17:12 nathan341

@nathan341 you did not mention on what gem version or master commit hash you encountered this.

Faq avatar Dec 17 '22 07:12 Faq

I'm using the latest mysql2 gem 0.5.5. and i'm having this issue. How do we tell ruby gem to use caching_sha2_password.

codezninja avatar Nov 06 '23 21:11 codezninja

I am having the exact same issue.

/usr/local/bundle/gems/mysql2-0.5.5/lib/mysql2/client.rb:97:in `connect': Mysql2::Error: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/x86_64-linux-gnu/mariadb18/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory (Sequel::DatabaseConnectionError)
	from /usr/local/bundle/gems/mysql2-0.5.5/lib/mysql2/client.rb:97:in `initialize'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/adapters/mysql2.rb:43:in `new'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/adapters/mysql2.rb:43:in `connect'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/connecting.rb:248:in `new_connection'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/connection_pool.rb:161:in `make_new'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/connecting.rb:276:in `synchronize'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/connecting.rb:302:in `test_connection'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/misc.rb:188:in `initialize'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/connecting.rb:57:in `new'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/database/connecting.rb:57:in `connect'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/core.rb:124:in `connect'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/core.rb:412:in `adapter_method'
	from /usr/local/bundle/gems/sequel-5.74.0/lib/sequel/core.rb:419:in `block (2 levels) in def_adapter_method'
	from /usr/src/app/config/development.rb:16:in `<top (required)>'
	from /usr/local/bundle/gems/elastic-apm-3.5.0/lib/elastic_apm/spies.rb:73:in `require'
	from /usr/local/bundle/gems/elastic-apm-3.5.0/lib/elastic_apm/spies.rb:73:in `require'
	from /usr/src/app/app.rb:204:in `<top (required)>'
	from /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /usr/src/app/bin/util:7:in `<main>'

vardaanmittal09 avatar Nov 20 '23 15:11 vardaanmittal09