Migración de datos de combate-MySQL de base de datos NoSQL a la base de datos MongoDB

Migrar datos de MySQL a la base de datos MongoDB

Prefacio

Este entorno se basa en el sistema Centos 7.8 para crear un entorno de aprendizaje mongodb-enterprise-4.2.8. Para
una construcción específica, consulte la construcción del entorno mongodb-enterprise-4.2.8.


Preparación de la máquina

  • node01: mongodb-enterprise-4.2.8
  • node02: mysql-5.7.14
# mysql 到处数据
[root@mysql-binary ~]# mysql -uroot -p123456
mysql> select user,host,authentication_string from mysql.user
    -> into outfile '/tmp/user.csv'
    -> fields terminated by ','
    -> optionally enclosed by '"'
    -> escaped by '"'
    -> lines terminated by '\r\n';
Query OK, 2 rows affected (0.00 sec)

[root@mysql-binary ~]# ll /tmp/user.csv 
-rw-rw-rw- 1 mysql mysql 133 Feb 17 20:29 /tmp/user.csv
[root@mysql-binary ~]# cat /tmp/user.csv
"root","localhost","*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9"
"mysql.sys","localhost","*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE"




# 导入mysql数据
[root@node01 ~]# mongoimport -h 192.168.5.11:27017 -d my_mongodb -c user -f user,host,authentication_string --type=csv /tmp/user.csv 
2021-02-17T20:36:13.737+0800	connected to: mongodb://192.168.5.11:27017/
2021-02-17T20:36:13.738+0800	2 document(s) imported successfully. 0 document(s) failed to import.


# 查看导入数据
MongoDB Enterprise > use my_mongodb
switched to db my_mongodb
MongoDB Enterprise > db.user.find()
{
    
     "_id" : ObjectId("602d07611ea3f6d057d37c2c"), "id" : 201, "name" : "张三", "age" : 19 }
{
    
     "_id" : ObjectId("602d07611ea3f6d057d37c2d"), "id" : 202, "name" : "李四", "age" : 22 }
{
    
     "_id" : ObjectId("602d07611ea3f6d057d37c2e"), "id" : 203, "name" : "王五", "age" : 20 }
{
    
     "_id" : ObjectId("602d07611ea3f6d057d37c2f"), "id" : 204, "name" : "赵六", "age" : 21 }
{
    
     "_id" : ObjectId("602d07611ea3f6d057d37c30"), "id" : 205, "name" : "钱七", "age" : 20 }
{
    
     "_id" : ObjectId("602d0dbdac3214d01854cb74"), "user" : "root", "host" : "localhost", "authentication_string" : "*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9" }
{
    
     "_id" : ObjectId("602d0dbdac3214d01854cb75"), "user" : "mysql.sys", "host" : "localhost", "authentication_string" : "*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE" }

¡La migración de datos de MySQL es exitosa! ! !

Supongo que te gusta

Origin blog.csdn.net/XY0918ZWQ/article/details/113837589
Recomendado
Clasificación