【发布时间】:2018-08-08 13:29:02
【问题描述】:
我正在尝试使用工具 Mongify 将 Mysql DB 迁移到 MongoDB,方法是参考 documentation:
我已经看到,关于此类迁移的帖子已经很少,但他们提到了 Rails 应用程序的问题以及对 Rails 的一些依赖关系。但是,就我而言,这只是没有 Rails 的简单迁移。
环境详情:
Windows 企业版 7
Mysql 社区服务器:5.7
Mongo 数据库服务器:4.0
ruby : ruby 2.5.1p57(2018-03-29 修订版 63029)[i386-mingw32]
Mysql c 连接器(32 位)
mysql 服务器和 mongo db 服务器作为服务运行良好。
rubygems 环境详情如下:
RubyGems Environment:
- RUBYGEMS VERSION: 2.7.6
- RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby25/lib/ruby/gems/2.5.0
- USER INSTALLATION DIRECTORY: C:/Users/irfan.sayed/.gem/ruby/2.5.0
- RUBY EXECUTABLE: C:/Ruby25/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby25/bin
- SPEC CACHE DIRECTORY: C:/Users/irfan.sayed/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby25/lib/ruby/gems/2.5.0
- C:/Users/irfan.sayed/.gem/ruby/2.5.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- C:\windows\system32
- C:\windows
- C:\windows\System32\Wbem
- C:\Program Files (x86)\Microsoft Application Virtualization Client
- C:\Program Files\PuTTY\
- C:\apache-maven-3.5.2-bin\apache-maven-3.5.2\bin
- "C:\Program Files\Java\jdk1.8.0_151\bin"
- C:\Program Files\Git\cmd
- C:\HashiCorp\Vagrant\bin
- C:\windows\System32\WindowsPowerShell\v1.0\
- C:\windows\System32\WindowsPowerShell\v1.0\
- C:\Ruby25\bin
- C:\Program Files\MySQL\MySQL Server 8.0\bin
- C:\Program Files\MongoDB\Server\4.0\bin
本地安装的 Gems 如下:
activemodel (5.2.1, 4.2.10)
activerecord (5.2.1, 4.2.10)
activerecord-mysql2-adapter (0.0.3)
activesupport (5.2.1, 4.2.10)
arel (9.0.0, 6.0.4)
awesome_print (1.8.0)
backports (3.11.3)
bigdecimal (default: 1.3.4)
bson (1.12.5)
bson_ext (1.12.5)
builder (3.2.3)
bundler (1.16.3)
byebug (10.0.2)
cmath (default: 1.0.0)
coderay (1.1.2)
concurrent-ruby (1.0.5)
coolline (0.5.0)
csv (default: 1.0.0)
cucumber (3.1.2)
cucumber-core (3.2.0)
cucumber-expressions (6.0.1)
cucumber-tag_expressions (1.1.1)
cucumber-wire (0.0.1)
date (default: 1.0.0)
dbm (default: 1.0.0)
did_you_mean (1.2.0)
diff-lcs (1.3)
etc (default: 1.0.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.0.2)
gdbm (default: 2.0.0)
gherkin (5.1.0)
highline (1.7.8)
i18n (0.9.5, 0.7.0)
io-console (default: 0.4.6)
ipaddr (default: 1.2.0)
jazz_fingers (5.0.0)
json (default: 2.1.0)
metaclass (0.0.4)
method_source (0.9.0)
minitest (5.11.3, 5.10.3)
mocha (1.6.0)
mongify (1.3.2)
mongo (1.12.5)
multi_json (1.13.1)
multi_test (0.1.2)
mysql (2.9.1 x86-mingw32)
mysql2 (0.5.2 x86-mingw32)
net-telnet (0.1.1)
openssl (default: 2.1.0)
pg (1.0.0 x86-mingw32)
power_assert (1.1.1)
pry (0.11.3)
pry-byebug (3.6.0)
pry-coolline (0.2.5)
psych (default: 3.0.2)
rake (12.3.1, 12.3.0, 11.3.0)
rdoc (default: 6.0.1)
rspec (2.99.0)
rspec-collection_matchers (1.1.3)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
rspec-mocks (2.99.4)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
sqlite3 (1.3.13 x86-mingw32)
stringio (default: 0.0.1)
strscan (default: 1.0.0)
test-unit (3.2.7)
thread_safe (0.3.6)
tzinfo (1.2.5)
unicode_utils (1.4.0)
watchr (0.7)
webrick (default: 1.4.2)
xmlrpc (0.3.0)
yard (0.9.15)
zlib (default: 1.0.0)
bundle install 和 bundle update 命令运行良好。所有依赖项都是 gem 已正确解析并在 ruby 的默认文件夹中可用。
database.config 文件使用如下:
sql_connection do
adapter "mysql2"
host "localhost"
username "root"
password "<password>"
database "abc"
end
mongodb_connection do
host "localhost"
database "db"
end
但是出现以下错误:
mongify check database.config
Traceback (most recent call last):
10: from C:/Ruby25/bin/mongify:23:in `<main>'
9: from C:/Ruby25/bin/mongify:23:in `load'
8: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/bin/mongify:17
:in `<top (required)>'
7: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/lib/mongify/cl
i/application.rb:28:in `execute!'
6: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/lib/mongify/cl
i/command/worker.rb:68:in `execute'
5: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/lib/mongify/cl
i/command/worker.rb:99:in `check_sql_connection'
4: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/lib/mongify/da
tabase/sql_connection.rb:56:in `has_connection?'
3: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mongify-1.3.2/lib/mongify/da
tabase/sql_connection.rb:40:in `setup_connection_adapter'
2: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activerecord-4.2.10/lib/acti
ve_record/connection_handling.rb:50:in `establish_connection'
1: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activerecord-4.2.10/lib/acti
ve_record/connection_adapters/connection_specification.rb:174:in `spec'
C:/Ruby25/lib/ruby/gems/2.5.0/gems/activerecord-4.2.10/lib/active_record/connect
ion_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mys
ql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your
Gemfile (and ensure its version is at the minimum required by ActiveRecord). (G
em::LoadError)
无法理解仍然缺少什么。是 MySQL 适配器的问题还是某些版本兼容性问题
编辑:根据 matthewd 的建议进一步更新
我编辑了 Gemfile 并添加了以下行
s.add_development_dependency('mysql2', '~> 0.4.10')
运行了 bundle update --force , bundle install --force 但它仍然只安装 mysql2 gem 的 0.5.x 版本
所以我使用以下命令手动安装了 0.4.10 版本的 mysql2 gem
gem install mysql2 -v 0.4.10
但现在它给出了以下错误
11: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10-x86-mingw32/li
b/mysql2.rb:31:in `<top (required)>'
10: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:274:in `require'
9: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:240:in `load_dependency'
8: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:274:in `block in require'
7: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59
:in `require'
6: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59
:in `require'
5: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/mysql2-0.4.10-x86-mingw32/li
b/mysql2/mysql2.rb:2:in `<top (required)>'
4: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:274:in `require'
3: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:240:in `load_dependency'
2: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/activesupport-4.2.10/lib/act
ive_support/dependencies.rb:274:in `block in require'
1: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59
:in `require'
C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': Co
uld not load 'active_record/connection_adapters/mysql2_adapter'. Make sure that
the adapter in config/database.yml is valid. If you use an adapter other than 'm
ysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the
Gemfile. (LoadError)
【问题讨论】: