2

环境

  • Rails version: 6.0.0.rc2
  • Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580)
  • RDS MySql: Ver 8.0.15

问题

我正在尝试将我的 RDS MySQL8 实例连接到我的本地 Ruby on Rails 应用程序以进行测试。我的应用程序在本地版本MySQL8.0.12mysql2gem 上运行良好。

当我使用 RDS DB 的详细信息并bin/rake db:[anything] VERBOSE=true在命令行中运行时,它只是挂起,而没有提供任何关于它为什么不工作的信息。下面输出。

这纯粹是为了测试我想用于登台环境的数据库。

  • 我已经从命令行连接到 RDS DB,从本地计算机连接到 DBeaver,并且我已经能够创建新表,因此安全组应该没问题。
  • 我使用了下面的数据库连接测试脚本来确保这ActiveRecord::Base.connected是真的
  • 以防万一,连接、启动、迁移和播种本地 mysql 数据库。

database.yml

#
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: [aws_rds_host_url]
  username:  <%= ENV.fetch("DB_USERNAME") %>
  password: <%= ENV.fetch("DB_PASSWORD") %>
  database: db_name

在 stackoverflow 上的某处找到的测试脚本(返回“已连接!”)

require './config/environment.rb' # Assuming the script is located in the root of the rails app
begin
  ActiveRecord::Base.establish_connection # Establishes connection
  ActiveRecord::Base.connection # Calls connection object
  puts "CONNECTED!" if ActiveRecord::Base.connected?
  puts "NOT CONNECTED!" unless ActiveRecord::Base.connected?
rescue StandardError => e
  puts e
  puts "rescue:: NOT CONNECTED!"
end

运行bin/rake db:create VERBOSE=true|| bin/rake db:migrate VERBOSE=true(或任何东西rake db:)一直挂着,试了一个多小时。它不会对数据库进行任何更改。用 cmd+C 停止,它只返回:

bin/rake db:create VERBOSE=true                                                                                                                                                        
^CTraceback (most recent call last):
    14: from bin/rake:3:in `<main>'
    13: from bin/rake:3:in `load'
    12: from [home]/[project dir]/bin/spring:16:in `<top (required)>'
    11: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    10: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     9: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
     8: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
     7: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
     6: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
     5: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
     4: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:35:in `call'
     3: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:42:in `warm_run'
     2: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:62:in `run'
     1: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `verify_server_version'
[home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `gets': Interrupt

4

0 回答 0