我试图通过参考以下文档,使用工具mongify将mysql db迁移到mongodb:
我已经看到,关于这种迁移的文章已经很少了,但是他们提到了rails应用程序的问题和对rails的一些依赖性。然而,在我的例子中,这只是没有rails的简单迁移。
环境详情:
windows企业版7
mysql社区服务器:5.7
mongo db服务器:4.0
ruby:ruby 2.5.1p57(2018-03-29修订版63029)[i386-mingw32]
mysql c连接器(32位)
mysql服务器和mongodb服务器作为一种服务运行良好。
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` 命令运行正常。所有依赖项都是正确解析的,并且可以在ruby的默认文件夹中使用。 `database.config` 使用的文件如下:
sql_connection do
adapter "mysql2"
host "localhost"
username "root"
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适配器的问题还是版本兼容性问题
编辑:根据马修德的建议进一步更新
我编辑了这个文件并添加了以下行
s.add_development_dependency('mysql2', '~> 0.4.10')
运行 `bundle update --force` , `bundle install --force` 但它仍然只安装了mysql2gem的0.5.x版本,所以我使用以下命令手动安装了mysql2gem的0.4.10版本
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)
2条答案
按热度按时间pu3pd22g1#
错误消息具有误导性:您使用的是
mysql2
gem对于activerecord4.2.10(最新版本)来说太新了mongify
支架)。最简单的解决方案是显式使用
mysql2
通过在文件条目中包含版本约束:7lrncoxx2#
终于解决了。它有ruby版本和32位库的问题。Ruby2.3经过了适当的测试,可以与MongifGem配合使用。我使用的是最新版本的ruby,这就是问题所在。