如何通过Ruby'连接到MySQL;s";mysql2“;宝石
我安装了一个新的MySQL实例,并尝试通过MySQL工作台(使用IP地址、默认端口、用户名/密码)连接到该实例。连接成功。所以这些值是正确的 然后,我创建了一个新的数据库模式“newDB”,并为同一个用户授予了newDB的所有特权 接下来,我将使用以下ruby代码连接到这个MySQL实例如何通过Ruby'连接到MySQL;s";mysql2“;宝石,mysql,ruby,sequel,Mysql,Ruby,Sequel,我安装了一个新的MySQL实例,并尝试通过MySQL工作台(使用IP地址、默认端口、用户名/密码)连接到该实例。连接成功。所以这些值是正确的 然后,我创建了一个新的数据库模式“newDB”,并为同一个用户授予了newDB的所有特权 接下来,我将使用以下ruby代码连接到这个MySQL实例 require 'fileutils' require 'logger' require 'sequel' require 'mysql2' DATABASE_URL = 'mysql2://The.IP.A
require 'fileutils'
require 'logger'
require 'sequel'
require 'mysql2'
DATABASE_URL = 'mysql2://The.IP.Address:3306'
DB_OPTIONS = { encoding: 'utf8', sql_log_level: :debug, adapter: "mysql2", database: "newDB", password: 'password123', username: 'someUser', host:'The.IP.Address', port:'3306' }
database_connection = Sequel.connect(DATABASE_URL, DB_OPTIONS.merge(logger: database_logger))
但是,此连接失败。以下是stacktrace:
13: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/core.rb:124:in `connect'
12: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/database/connecting.rb:57:in `connect'
11: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/database/connecting.rb:57:in `new'
10: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/database/misc.rb:169:in `initialize'
9: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/database/connecting.rb:278:in `test_connection'
8: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/database/connecting.rb:269:in `synchronize'
7: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
6: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
5: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/connection_pool.rb:122:in `make_new'
3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/adapters/mysql2.rb:43:in `connect'
2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sequel-5.44.0/lib/sequel/adapters/mysql2.rb:43:in `new'
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:90:in `initialize'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:90:in `connect': Mysql2::Erro (Sequel::DatabaseConnectionError)sha2_password' cannot be loaded: The specified module could not be found.
如何修复此错误?我似乎已经为主机名、用户名等提供了正确的值。我终于解决了这个问题。存在多个问题: