当前位置:网站首页>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
边栏推荐
- 推荐一款 JSON 可视化工具神器!
- 选择在中金证券上炒股开户可以吗?安全吗?
- 106. construct binary tree from middle order and post order traversal sequence
- 【Laravel 】faker数据填充详解
- 新一代云原生数据库的设计与实践
- 12 product management platforms that everyone is using
- CRC check
- NC | 肠道细胞和乳酸菌共同作用来防止念珠菌感染
- Prefabricated dishes usher in the "golden age", who can lead the next trillion market
- 数字藏品市场新局面
猜你喜欢
![C# [字节数组]与[16进制字符串]互相转换 - CodePlus系列](/img/d2/dad88f53701c7cd7638bd4983cbb4b.png)
C# [字节数组]与[16进制字符串]互相转换 - CodePlus系列

Suggest collecting | what to do when encountering slow SQL on opengauss?
![[dark horse morning post] Yu Minhong said he never looked at the stock price of New Oriental; Hengchi 5 will start pre-sale in July; Naixue virtual stock or suspected of illegal fund-raising; From Jul](/img/58/8d5c78d919ed60bc833ec4daa22e23.jpg)
[dark horse morning post] Yu Minhong said he never looked at the stock price of New Oriental; Hengchi 5 will start pre-sale in July; Naixue virtual stock or suspected of illegal fund-raising; From Jul

Error: missing revert data in call exception

JS基础--数据类型
![[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》](/img/b3/b117481fba7257453011e4cdb1eaaa.png)
[.NET6]使用ML.NET+ONNX预训练模型整活B站经典《华强买瓜》

Japanese professor sues Intel FPGA and SOC products for infringing a design patent

Continue to advance, and softcom power steadily promotes cloud intelligence strategy

价值1000毕业设计校园信息发布平台网站源码

CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
随机推荐
【邂逅Django】——(二)数据库配置
Half of 2022 has passed, isn't it sudden?
MySQL常用命令
. Net 5.0+ does not need to rely on third-party native implementation of scheduled tasks
C one line code calculates the MD5 value of the file - codeplus series
Sqlachemy common operations
北汽蓝谷:业绩承压,极狐难期
想请教一下,我在广州,到哪里开户比较好?现在网上开户安全么?
选择在中金证券上炒股开户可以吗?安全吗?
想开个户,在网上开华泰证券的户安全吗?
移动硬盘驱动器读到,但不显示盘符
I'd like to know where I can open an account in Guangzhou? Is it safe to open an account online now?
华为HMS Core携手超图为三维GIS注入新动能
CRC 校驗
【MPC】①二次规划问题MATLAB求解器quadprog
Matplotlib data visualization Foundation
leetcode:111. Minimum depth of binary tree
Project0: Games
The list of winners of the digital collection of "century master" was announced
How to get the maximum value of column two and regenerate the table when the SQL Server column one is the same