当前位置:网站首页>How does MySQL copy table data from one database to another (two databases are not linked to the same database)
How does MySQL copy table data from one database to another (two databases are not linked to the same database)
2022-07-01 10:46:00 【12 procedural ape】
Catalog
1. demand :
hold A database connection ( Such as :test) A table in a database in ( Such as :warn_message) The data of , Batch copy to Another database connection ( Such as :localhost) A table in a database in ( Such as :warn_message) in
Two warn_message The data structure of the table is consistent
2. Realization
mysql Batch add statements :
insert into Table name ( Field 1, Field 2, Field 3)values ( Field 1 Value , Field 1 Value , Field 1 Value ),( Field 1 Value , Field 1 Value , Field 1 Value );
The next step is to assemble values hinder value , To achieve the effect of batch replication :
2.1 Put the data to be copied Copy and paste to excel in


2.2 Handle excel Data in
Then modify according to the requirements excel Data in , Such as Delete self incrementing primary key id, Modification of special formats such as time fields
hold excel Assemble into It can be in batches Added parameters
① Delete id Column
② Chinese content 、 Time column Both ends add to Single quotation marks
Select the Chinese column , Right click —》 Format cell —》 Check customize , Select the following types , Add Single quotation marks , Click ok :

Time column Same treatment :


③ Beginning and end of each line add to Brackets


④ Null values should be processed into null perhaps Empty single quotation mark
If you don't deal with , Will report a mistake , See below .
⑤ file save as *.csv file

Select in the pop-up window yes :

⑥ In the form of Notepad Open the top 333.csv file


Find the contents in Notepad leave The goal is Almost , More Double quotes !!!
resolvent : Global replacement “”, Get the following :
2.3 Copy the contents of the Notepad to mysql Client tools , Splicing Batch insert statements

Error report in execution : explain Null values should also be processed . Processing into null Or an empty string 
After processing the sql The sentence is :
INSERT INTO `warn_message`(`device_id`, `device_type`, `extend_json`, `install_place_id`, `pound_order_id`, `rational_deviation`, `real_deviation`, `overtime_duration`, `warn_type`, `deal_flag`, `deal_result`, `active_flag`, `created_user`, `created_time`, `updated_user`, `updated_time`, `warning_level`, `organization_id`, `start_time`, `end_time`, `description`, `resolver`, `third_warn_id`, `relation_user_id`) VALUES
(1842,8,null,102,0,0,0,0,0,1,' The system automatically cancels the alert ',1,0,'2021/2/3 11:23',0,'2021/2/3 14:40',3,1047,'2021/2/3 11:23','2021/2/3 14:40',null,null,6534,null),
(1842,8,null,102,0,0,0,0,0,1,' The system automatically cancels the alert ',1,0,'2021/2/3 11:43',0,'2021/2/3 14:40',3,1047,'2021/2/3 11:43','2021/2/3 14:40',null,null,6534,null),
(1842,8,null,102,0,0,0,0,0,0,' The system automatically cancels the alert ',1,0,'2021/2/3 12:11',0,'2021/2/3 13:56',3,1047,'2021/2/3 12:11','2021/2/3 13:56',null,null,6534,null),
(1842,8,null,102,0,0,0,0,8,1,' The system automatically cancels the alert ',1,0,'2021/2/3 13:56',0,'2021/9/30 11:48',3,1047,'2021/2/3 13:56','2021/2/3 14:40',' Fireworks ',null,6534,null),
(1842,8,null,102,0,0,0,0,8,1,' The system automatically cancels the alert ',1,0,'2021/2/3 13:59',0,'2021/9/30 11:48',3,1047,'2021/2/3 13:59','2021/2/3 14:40',' Fireworks ',null,6534,null),
(1842,8,null,102,0,0,0,0,8,1,' The system automatically cancels the alert ',1,0,'2021/2/3 14:06',0,'2021/9/30 11:48',3,1047,'2021/2/3 14:06','2021/2/3 14:40',' Fireworks ',null,6534,null),
(1842,8,null,102,0,0,0,0,8,1,' The system automatically cancels the alert ',1,0,'2021/2/3 14:10',0,'2021/9/30 11:48',3,1047,'2021/2/3 14:10','2021/2/3 14:40',' Fireworks ',null,6534,null),
(1842,8,null,102,0,0,0,0,8,0,' The system automatically cancels the alert ',1,0,'2021/2/3 14:40',0,'2021/9/30 11:48',3,1047,'2021/2/3 14:40',null,' Fireworks ',null,6534,null)
The operation results are as follows :

Batch insert succeeded !!
2.4 Be careful :excel Hollow values also need to be handled
excel Data in Handle the points needing attention :
① Chinese and time All need to be added Single quotation marks
② Null values also need to be processed Processing into null perhaps Empty Single quotation marks
边栏推荐
- .NET 5.0+ 无需依赖第三方 原生实现定时任务
- 爬虫(2) - Requests(1) | Requests模块的深度解析
- Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
- Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
- 零基础入门测试该学什么?最全整理,照着学就对了
- 442. 数组中重复的数据
- 基金国际化的发展概况
- Matplotlib data visualization Foundation
- Design and practice of new generation cloud native database
- Wireshark TS | confusion between fast retransmission and out of sequence
猜你喜欢

Matplotlib数据可视化基础

Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched

机器学习之线性回归详解

Rising stars in Plant Sciences (rsps2022) final Science Lecture (6.30 pm)

Error: missing revert data in call exception

新品大揭秘!雅迪冠能 3 多元产品矩阵,满足全球用户出行需求

零基础入门测试该学什么?最全整理,照着学就对了

Design and practice of new generation cloud native database

使用强大的DBPack处理分布式事务(PHP使用教程)

Wireshark TS | 快速重传和乱序之混淆
随机推荐
关于#数据库#的问题:GBase 8s中如何避免死锁
[paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba
【MPC】②quadprog求解正定、半正定、负定二次规划
想开个户,在网上开华泰证券的户安全吗?
Suggest collecting | what to do when encountering slow SQL on opengauss?
Continue to advance, and softcom power steadily promotes cloud intelligence strategy
Does anyone know why? The table structure is the source table MySQL CDC that has just been directly copied
Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
Prism journal navigation button usability exploration record
678. Valid bracket string
Venv: directory structure of venv
使用强大的DBPack处理分布式事务(PHP使用教程)
[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》
Can MySQL CDC take out the op field
Programmers want to go to state-owned enterprises? The technology is backward and the salary is low. I can't find a job after lying flat for several years
Want to open an account, is it safe to open an account of Huatai Securities online?
CRC check
华为HMS Core携手超图为三维GIS注入新动能
新一代云原生数据库的设计与实践
选择在中金证券上炒股开户可以吗?安全吗?