Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Export the specified field of mongodb data, and then import the specified field into the mysql instance and solve related problems

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Requirements: export the specified fields of mongodb data, and then import the specified fields into the mysql table

Go straight to the picture.

Finally, several problems encountered and solutions will be posted so that similar problems can be solved quickly (the specific usage of the commands used during this period is not included in the detailed explanation of this article)

Export the specified field of mongodb data, use the command Mongoexport, and consult the official document.

Export specified secondary field Mongodb

/ opt/mongodb/bin/mongoexport-host yourip-port yourport-d app_form-c application_data-csv-out export2.csv-fields applicant.name,applicant.id_card_num,applicant.cell_phone_num,applicant.home_addr

two。 If the rsync is transmitted on the mysql machine, the usage of rysnc will not be mentioned.

Rsync-chavzP-- stats yourusername@yourip:/home/mongodata/export.csv / data/mysql/

3. To import mysql, there are two cases, one is to import a new table, the other is to import an existing table, but you need to specify the specific fields of the table

New Table:

LOAD DATA INFILE'/ data/mysql/export2.csv' INTO TABLE temp_test CHARACTER SET utf8 FIELDS TERMINATED BY', 'ENCLOSED BY' "'

The fields specified in the old table:

LOAD DATA INFILE'/ data/mysql/export2.csv' INTO TABLE temp_test2 CHARACTER SET utf8mb4 FIELDS TERMINATED BY', 'ENCLOSED BY' "'(name,idcard,tellnumber, address)

The result verifies:

Import succeeded

4. Correct Export method of Secondary Field in 1:mongo Export of knotty and complicated Diseases

4. ERROR 1366 (HY000): Incorrect string value:'\ xF0\ xA5\ x8C\ x93\ xE5\ x85. 'during the introduction of 2:mysql. For column 'address' at row 45293 solution

This problem is very difficult to solve. It is generally believed that utf8mb4 is caused. The specific reason is that you need to modify the default character set of the table and import it with a specified utf8mb4.

You can modify ALTER TABLE temp_test2 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 1.

4. Difficult and complicated 3:mongo import ERROR 1262 (01000): Row 1066659 was truncated; it contained more data than there were input columns solution, sql_mode problem, need to be modified

5. Other problems, such as duplicate primary keys, field sizes that do not meet the requirements, and other minor problems can be solved by themselves.

Finally, the normal results show that:

Few of the posts found in Baidu can solve such problems, and none of them are complete examples. I hope it will be helpful to all of you.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report