使用mongify将sqlserver数据导入到mongodb
最近需要将sqlserver数据导入到mongodb中,在github上搜了一圈,发现两个项目有点适合
先试了下sql2mongodb(有个好名字果然有好处啊), 可是,but,但是,这东西好像并不没有名字取得好,试了下感觉不靠谱,弃坑,逃~~~
说点题外话,sql2server以来nodejs, mongify依赖ruby, 这两个库都是我最讨厌的,暂时没有理由。
好了,现在咱专注mongify吧
先看官网介绍:
Mongify是一个将数据从sql数据库转换到mongoDB的ruby工具。支持MySQL,PostgreSQL,SQLite,Oracle,SQLServer和DB2(基本上ActiveRecord内置的内容),支持任何版本的MongoDB。
但是,缺点是作者声称只在MySql和SQLite测试过,对于我现在需要的sqlserver,心中一群在奔腾。。。
安装
使用的环境是ubuntu12.04,该版本软件仓库中的ruby是1.8版本的,需要ruby2.1版本以上才行
- 省懒,直接加ppa吧, 这里可以随便安装到2.3版本
From the travis-cli installation instructions for Ubuntu, the Brightbox Ruby NG(NextGeneration) ppa:
$ sudo apt-get install python-software-properties
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby2.1 ruby-switch
$ sudo ruby-switch --set ruby2.1
顺便注明下gem的使用吧
ubuntu@aws:~$ gem --help
RubyGems is a sophisticated package manager for Ruby. This is a
basic help message containing pointers to more information.
Usage:
gem -h/--help
gem -v/--version
gem command [arguments...] [options...]
Examples:
gem install rake
gem list --local
gem build package.gemspec
gem help install
Further help:
gem help commands list all 'gem' commands
gem help examples show some examples of usage
gem help gem_dependencies gem dependencies file guide
gem help platforms gem platforms guide
gem help <COMMAND> show help on COMMAND
(e.g. 'gem help install')
gem server present a web page at
http://localhost:8808/
with info about installed gems
Further information:
http://guides.rubygems.org
好,那我们安装mongify吧gem install mongify
经过一轮踩坑,还是关注下mongify目录结构吧 其中有一个文件mongify.gemspec
$:.push File.expand_path("../lib", __FILE__)
require "mongify/version"
Gem::Specification.new do |s|
s.name = "mongify"
s.version = Mongify::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Andrew Kalek"]
s.email = ["andrew.kalek@anlek.com"]
s.homepage = "http://mongify.com"
s.summary = %q{Translate your SQL data to MongoDB with ease}
s.description = %q{Mongify allows you to map your sql data into a mongodb document database with a simple DSL.}
s.required_ruby_version = ">= 1.8.7"
s.add_runtime_dependency('activerecord', ">= 4.2", "< 5.0")
s.add_runtime_dependency('activesupport', ">= 4.2", "< 5.0")
s.add_runtime_dependency('mongo', "= 1.12.5")
s.add_runtime_dependency('bson', "= 1.12.5")
s.add_runtime_dependency('bson_ext', "= 1.12.5") unless RUBY_PLATFORM == 'java'
s.add_runtime_dependency('highline', '= 1.7.8')
s.add_development_dependency('rspec', '~> 2.0')
s.add_development_dependency('rspec-collection_matchers', '~> 1.0')
s.add_development_dependency('cucumber', '>= 0.10')
s.add_development_dependency('mocha', '>= 0.9.8')
s.add_development_dependency('yard', '>= 0.8')
s.add_development_dependency('sqlite3', '>= 1.3')
s.add_development_dependency('pg', '>= 0.17')
s.add_development_dependency('mysql2', '>= 0.4')
s.add_development_dependency('watchr', '>= 0.6')
s.add_development_dependency('rake')
s.add_development_dependency('jazz_fingers')
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.extra_rdoc_files = [
"CHANGELOG.md",
"README.rdoc"
]
s.rdoc_options = ["--title", "Mongify -- SQL db to Mongo db converter", "--main", "README", "--line-numbers", "--inline-source"]
end
可以看到这里指定了依赖,对版本也有要求。
如果已经安装过mongify1.3.1版本的话,导出sqlserver数据库时将会发现如果要支持sqlserver数据库还需要安装activerecord-sqlserver-adapter
而在activerecord-sqlserver-adapter
官网有这样的描述
The SQL Server adapter for ActiveRecord v5.0 using SQL Server 2012 or higher.
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 5.0.x version of the adapter is only for the latest 5.0 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.
由于我的sqlserver是2008版本的,也就是说我最高可以使用4.1.x版本,并且最好有配套的ActiveRecord
所以我选择了1.2.4版本的Mongify,可以看下这个版本的依赖
s.add_dependency('activerecord', "~> 3.2")
s.add_dependency('activesupport', "~> 3.2")
s.add_dependency('mongo', "~> 1.10.2")
s.add_dependency('bson', "~> 1.10.2")
s.add_dependency('bson_ext', "~> 1.10.2") unless RUBY_PLATFORM == 'java'
s.add_dependency('highline', '>= 1.6.1')
对应的可以满足3.2.x-4.1.x这个要求,那么就是他了
重新安装Mongify
gem install mongify -v 1.2.4
根据上面的依赖,会安装对应版本软件再安装activerecord-sqlserver-adapter
gem install activerecord-sqlserver-adapter -v 3.2.17
创建配置文件
为了让Mongify正常工作,它需要知道数据库的位置及连接信息。
构建配置文件就像这样简单: (对于我们,adapter需要改成sqlserver)
sql_connection do
adapter "mysql"
host "localhost"
username "root"
password "passw0rd"
database "my_database"
batch_size 10000 # This is defaulted to 10000 but in case you want to make that smaller (on lower RAM machines)
end
mongodb_connection do
host "localhost"
database "my_database"
end
检查配置文件
mongify check database.config
生成转换文件
如果您的数据库庞大而复杂,手工编写转换文件可能会有太多的工作。 Mongify的可以直接使用命令生成:
mongify translation database.config
可以使用重定向将配置输出到文件
mongify translation database.config > translation_file.rb
最后将sql数据导入到mongodb中
mongify process database.config translation_file.rb
导出时每次读取10000条数据,以进度条显示进度
Copying playsrc (261/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (262/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (263/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:02
Copying playsrc (264/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:02
Copying playsrc (265/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (266/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (267/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:02
Copying playsrc (268/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:02
Copying playsrc (269/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (270/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:03
Copying playsrc (271/607): (10000/10000) 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:02
附录Mongify的命令,总共就四个主要命令,以上用过了三个
Usage: mongify command database_config [database_translation.rb]
Commands:
"check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
"process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
"sync" or "sy" >> Takes a translation and process it to mongodb, only syncs (insert/update) new or updated records based on the updated_at column [configuration_file, translation_file]
"translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
Examples:
mongify translation datbase.config
mongify tr database.config
mongify check database.config
mongify process database.config database_translation.rb
mongify sync database.config database_translation.rb
Common options:
-h, --help Show this message
-v, --version Show version
使用mongify将sqlserver数据导入到mongodb的更多相关文章
- SQLSERVER数据导入到MYSQL
SQLSERVER数据导入到MYSQL http://hi.baidu.com/luck001221/item/cb4462299f9ea79ab73263d2?qq-pf-to=pcqq.group ...
- SQLServer 数据导入导出 SSIS 包 位置
笔记:sqlserver 在执行数据导入导出的时候,可以选择是否保存SSIS包,如果选择保存,在保存方式有:SQlserver .文件系统.如果选择sqlserver 则 包信息保存在 msdb 系统 ...
- python 读取SQLServer数据插入到MongoDB数据库中
# -*- coding: utf-8 -*-import pyodbcimport osimport csvimport pymongofrom pymongo import ASCENDING, ...
- SQLServer数据导入Mongodb
一.思路 MongoVUE免费版支持MySQL导入Mongo,所以思路是SQLServer导入MySQL,再从MySQL导入Mongo. 二.准备 1,安装mysql数据库(我用的是WAMP,集成my ...
- sqlserver数据导入导出问题
sqlserver,如果用结果另存为,导出txt数据,然后在导入数据库,有时候会出问题,很难解决. 但是全选,右击,复制到自己创建的txt里面,在导入数据,就不会有问题的. 神奇,不知道为什么,但是能 ...
- sqlserver数据导入问题:报错“对COM组件的调用返回了错误HRESULT E_FAIL”
SQL server 2008,导出了两个sql文件. 打开第一个文件,没有问题,建好相应的数据库,运行脚本,即可导入. 第二个文件却遇到问题,始终报错“对COM组件的调用返回了错误HRESULT E ...
- SqlServer数据导入到ORACLE
ORACLE中执行 select * from SYSTEM."employ_epl"
- 使用pandas把mysql的数据导入MongoDB。
使用pandas把mysql的数据导入MongoDB. 首先说下我的需求,我需要把mysql的70万条数据导入到mongodb并去重, 同时在第二列加入一个url字段,字段的值和第三列的值一样,代码如 ...
- 【实战】使用 Kettle 工具将 mysql 数据增量导入到 MongoDB 中
最近有一个将 mysql 数据导入到 MongoDB 中的需求,打算使用 Kettle 工具实现.本文章记录了数据导入从0到1的过程,最终实现了每秒钟快速导入约 1200 条数据.一起来看吧~ 一.K ...
随机推荐
- org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 启动hibernate测试案例时报错如下: 2.解决方案: 2.1 第一次解决:MySQL驱动版本太高.使用的hibernate版本为5 ...
- 安卓SAX解析XML文件
XML文件经常使用的解析方式有DOM解析,SAX解析. 一.Sax SAX(simpleAPIforXML)是一种XML解析的替代方法. 相比于DOM.SAX是一种速度更快,更有效的方法. 它逐行扫描 ...
- Atitit..jdk java 各版本新特性 1.0 1.1 1.2 1.3 1.4 1.5(5.0) 1.6(6.0) 7.0 8.0 9.0 attilax 大总结
Atitit..jdk java 各版本新特性 1.0 1.1 1.2 1.3 1.4 1.5(5.0) 1.6(6.0) 7.0 8.0 9.0 attilax 大总结 1.1. Java的编年史2 ...
- ssh不检查server变化
嵌入式linux开发时经常需要远程登录到板上,但由于开发过程还经常会重新下载内核和文件系统,导致登录时总提示host变了,blablabla,解决方案是在.ssh/config对应的Host项下面加上 ...
- File 的基本操作
package xinhuiji_day07; import java.io.File;import java.io.IOException; public class FileTest { /** ...
- eclipse JVM Tomcat 内存堆栈大小设置
1, 设置Eclipse内存使用情况 修改eclipse根目录下的eclipse.ini文件 -vmargs //虚拟机设置 -Xms40m //初始内存 -Xmx256m //最大内存 -Xmn ...
- ThinkPHP3.1URL分发BUG修正
请先留意以下PHP脚本 PHP脚本A(http://127.0.0.1:8110/test.php): $url = 'http://127.0.0.1:8110/demo.php'; //curl请 ...
- 10 Memcached 一致性哈希分布式算法原理与实现[PHP实现]
<?php header("Content-type:text/html;charset=utf-8"); interface hash{ public function _ ...
- Python爬上不得姐 并将段子写入数据库
#Python2.7 可以优化一下 前10页 每页点赞最多的段子 百思不得姐 # -*- coding: utf-8 -*-import MySQLdbimport urllib,urllib2imp ...
- Selenium+C#自动化脚本开发学习
1:Selenium中对浏览器的操作 首先生成一个Web对象 IWebDriver driver = new FirefoxDriver(); //打开指定的URL地址 driver.Navigate ...