首页 > 数据库 >mongodb数据迁移mysql

mongodb数据迁移mysql

时间:2024-07-30 14:54:59浏览次数:17  
标签:00 07 04 mongodb 2024 125 mysql 180025000847363438383733 迁移

1、安装MongoDB

参考链接

https://blog.csdn.net/qq_45664055/article/details/119794071

http://bbs.itying.com/topic/5bd675d80e525017c449479d

1.1 创建repo文件,MongoDB数据库不在yum的官方仓库,通过配置如下文件,可以通过yum下载MongoDB

vi /etc/yum.repos.d/mongodb-org-4.4.repo
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

[mongodb-org-4.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck=0 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

1.2 安装MongoDB

yum install -y mongodb-org

1.3 卸载MongoDB

systemctl stop mongod 关闭
 yum erase $(rpm -qa | grep mongodb-org) 卸载 
#删除数据及日志 
rm -rf /var/log/mongodb 
rm -rf /var/lib/mongo

1.4 修改MongoDB配置文件,允许远程连接

vi /etc/mongod.conf 
net: port: 27017 #数据库端口,如果要远程连接,服务器记得开放端口 
bindIp: 0.0.0.0 # 默认是 127.0.0.1 只限于本机连接,如果要远程连接修改为:0.0.0.0

1.5 启动MongoDB

service mongod start centos6的写法

systemctl start mongod centos7的写法

1.6 MongoDB的基本操作

客户端进入MongoDB:mongo

创建数据库 :use demo

创建表,并且数据 : db.w_demo.insert({"name":"王明","age":"10","grade":"小学"})

2、MongoDB可视化工具

3、创建表、添加测试数据

685758046e0fb0001dad8e8,340030000B47363438383733,8C780D32F900260383493808CC96,2024-07-04 00:00:00 055 6685758046e0fb0001dad8e9,340030000B47363438383733,8C79A06C39EE65FC81D828307124,2024-07-04 00:00:00 055 6685758046e0fb0001dad8ea,340030000B47363438383733,8C79A06C39EE632C2C12766ABC7D,2024-07-04 00:00:00 055 6685758046e0fb0001dad8eb,340030000B47363438383733,8C780D32381A65EEB9D6ACD107E7,2024-07-04 00:00:00 055 6685758046e0fb0001dad8ec,340030000B47363438383733,8C79A06C39EE65FC83D8242B91FC,2024-07-04 00:00:00 055 6685758046e0fb0001dadb53,180025000847363438383733,02818334223D7A,2024-07-04 00:00:00 125 6685758046e0fb0001dadb54,180025000847363438383733,8C7813B93818F058371851BB46ED,2024-07-04 00:00:00 125 6685758046e0fb0001dadb55,180025000847363438383733,A8001BAF809CEF25E00492C097AD,2024-07-04 00:00:00 125 6685758046e0fb0001dadb56,180025000847363438383733,8D78046A990C8E9DF09019F5FFD9,2024-07-04 00:00:00 125 6685758046e0fb0001dadb57,180025000847363438383733,02C18CB2F5ACA1,2024-07-04 00:00:00 125 6685758046e0fb0001dadb58,180025000847363438383733,200016303DA8AC,2024-07-04 00:00:00 125 6685758046e0fb0001dadb59,180025000847363438383733,02C18CB2F5ACA1,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5a,180025000847363438383733,02C189B8C3FFB4,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5b,180025000847363438383733,8D89805E584FE2AC38F4F65130D7,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5c,180025000847363438383733,02A185BA442656,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5d,180025000847363438383733,8D7805AF9909180C18041613AFAB,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5e,180025000847363438383733,02E18D1AB8F754,2024-07-04 00:00:00 125 6685758046e0fb0001dadb5f,180025000847363438383733,02A184B1B5AC11,2024-07-04 00:00:00 125 6685758046e0fb0001dadb60,180025000847363438383733,80618193580D32DD1EC5D965CAAF,2024-07-04 00:00:00 125 6685758046e0fb0001dadb61,180025000847363438383733,A000019389C80030A40000B08473,2024-07-04 00:00:00 125 6685758046e0fb0001dadb62,180025000847363438383733,A8001235FF731F13FFF453FB3E9D,2024-07-04 00:00:00 125 6685758046e0fb0001dadb63,180025000847363438383733,A00015BDC2980030A400000C9499,2024-07-04 00:00:00 125 6685758046e0fb0001dadb64,180025000847363438383733,02A18639AEDAAD,2024-07-04 00:00:00 125 6685758046e0fb0001dadb65,180025000847363438383733,8D780E409908D120F0482094F4EF,2024-07-04 00:00:00 125 6685758046e0fb0001dadb66,180025000847363438383733,5D75021BAFC19A,2024-07-04 00:00:00 125 6685758046e0fb0001dadb67,180025000847363438383733,02C18930C484A8,2024-07-04 00:00:00 125 6685758046e0fb0001dadb68,180025000847363438383733,A00015BDFFD9F93B2004E186573A,2024-07-04 00:00:00 125

pip install pymongo==4.4

加载数据到mysql数据库

4、Datax - mongodb reader

参考文章

https://www.cnblogs.com/LIAOBO/p/13666845.html

4.1源码修改

5、修改datax源码打包

对datax的所有模块进行打包,时间比较长

mvn -U clean package assembly:assembly '-Dmaven.test.skip=true'  

指定mongodbreader模块 以及 它所依赖的模块进行打包

mvn -U clean package -pl mongodbreader -am  assembly:assembly '-Dmaven.test.skip=true'

将idea中打的jar包上传到datax的mongodbreader下,替换原本的插件jar包

hutool工具类jar包上传到datax的mongodbreader的libs目录下

6、自己写的项目 已经打jar包

6.1添加依赖

6.2自定义函数,解析字段,生成系统时间(自己的需求)

6.3项目打jar包上传到/opt/installs/datax/plugin/reader/mongodbreader/libs/目录下

7、mysql建表

create table y_demo(
        device_code varchar(100),
        rev_time  varchar(100),
        msg_content  varchar(100),
        icao  varchar(100),
        msg_type  varchar(100),
        handle_time  varchar(100)
)

8.编写datax的json文件,并且测试运行

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "mongodbreader",
                    "parameter": {
                        "address": ["hadoop13:27017"],
                        "collectionName": "y_demo",
                        "column": [
                         {
                         "name":"deviceCode",
                         "type":"string"
                         },
                         {
                         "name":"revTime",
                         "type":"string"
                         },
                         {
                         "name":"rawDataContent",
                         "type":"string"
                         },
                         {
                         "name":"rawDataContent",
                         "type":"string",
                                                 "functionClassName":"com.demo.ParseContent",
                                                 "functionMethodName":"m1"
                         },
                         {
                         "name":"rawDataContent",
                         "type":"string",
                                                 "functionClassName":"com.demo.ParseContent",
                                                 "functionMethodName":"m2"
                         },
                         {
                         "type":"string",
                                                 "functionClassName":"com.demo.ParseContent",
                                                 "functionMethodName":"m3"
                         }
                        ],
                        "dbName": "demo",
                    }
                },
                "writer": {
                    "name": "mysqlwriter",
                    "parameter": {
                        "column": ["device_code","rev_time","msg_content","icao","msg_type","handle_time"],
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:mysql://hadoop11:3306/test1",
                                "table": ["y_demo"]
                            }
                        ],
                        "password": "123456",
                        "username": "root",
                        "writeMode": "insert"
                    }
                }
            }
        ],
        "setting": {
            "speed": {
                "channel": "1"
            }
        }
    }
}

运行datax文件:

python  bin/datax.py job/xxx.json

标签:00,07,04,mongodb,2024,125,mysql,180025000847363438383733,迁移
From: https://blog.csdn.net/weixin_56130021/article/details/140795713

相关文章

  • 忘记MySQL密码的处理措施(取消密码认证,直接登录)
    忘记MySQL密码/etc/my.cnf.d/mysql-server.cnf删除#号,取消注释skip-grant-tables选项下参数重启mysqld服务后,直接回车登录查看status状态直接修改密码无法成功,提示在skip-grant-tables选项下使用FLUSHPRIVILEGES;命令刷新权限即可回到上面删除掉skip-grant-tables......
  • MYSQL学习总结
    事务:一个不可拆分的操作,要么全部执行完,要么全都不执行;隔离级别:总共有四个,分别是ReadUncommitted(读取未提交内容),ReadCommitted(读取提交内容),RepeatableRead(可重读),Serializable(可串行化);ReadUncommitted(读取未提交内容):一个事务可以读取另一个事务未提交的数据;如果另一个事务......
  • 记一个kvm虚拟器迁移后无法启动故障
    参考https://www.cnblogs.com/joshua317/p/18061002故障现象kvm虚拟机从一台主机迁移至另外一台主机后启动失败报错信息如下#Type"journalctl"toviewsystemlogs.使用命令查看错误信息#Failedtomount/sysroot原因分析CentOS系统启动时出现Failedtomount......
  • Mysql时间互转
    第一种情况:日期转字符串1、函数:date_format(date,format)selectdate_format(now(),'%Y-%m-%d%H:%i:%S');第二种情况:日期转时间戳1、函数:unix_timestamp(data)selectunix_timestamp(now());第三种情况:字符串转日期1、函数:str_to_date(str,format);注:format格式必须......
  • MySQL安装
    1、安装成功的步骤#获取rpmsudorpm-Uvhhttps://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm#直接安装yuminstall-ymysql-community-server#查看服务systemctlstatusmysql2、安装成功后续#安装成功后续#启动systemctlstartmysqld.s......
  • 分享一个MySQL数据库表结构导出word文档最方便的方法
    原文链接:https://blog.csdn.net/typ1805/article/details/836587081、使用的是MySQL-Front工具,这个工具使用非常方便,尤其是导出数据的时候,几百万的数据一两分钟就导完了,推荐使用。MySQL-Front下载(只有3.93M):https://mysql-front.en.softonic.com/注:新版本和老版本的区别比较大,有......
  • 【MySQL】MySQL关系型数据库与非关系型数据库的比较及代码示例
    目录一、关系型数据库(RDBMS)概览1.1MySQL介绍1.2数据结构1.3事务处理二、非关系型数据库(NoSQL)概览2.1MongoDB介绍2.2数据结构2.3事务处理三、核心差异比较3.1数据结构3.2数据操作3.3可扩展性3.4事务处理四、实战技巧与建议五、总结        ......
  • 【MySQL】MySQL数据类型详解及代码示例
    目录数值类型整数类型浮点数和定点数类型字符串类型定长字符串(CHAR)可变长度字符串(VARCHAR)文本类型(TEXT)日期和时间类型二进制类型特殊类型        在数据库设计中,选择合适的数据类型对于数据库的性能和存储效率至关重要。MySQL作为最流行的关系型数据库管......
  • ubuntu 安装指定版本 mysql
    先访问 MySQL::MySQL8.4ReferenceManual::2.5.2InstallingMySQLonLinuxUsingtheMySQLAPTRepository 然后运行dpkg-i命令:     _________________________________________________________________________________________________________......
  • mongodb数据库范围分片数据分布不均匀
    【说明】当前使用mongodb分片,三个分片mongos>sh.status()---ShardingStatus---shardingversion:{"_id":1,"minCompatibleVersion":5,"currentVersion":6,"clusterId":ObjectId(&quo......