当前位置:网站首页>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
边栏推荐
- 442. duplicate data in array
- Prism journal navigation button usability exploration record
- Design and practice of new generation cloud native database
- SQL optimization - in and not in, exist
- MySQL common commands
- venv: venv 的目录结构
- NC | intestinal cells and lactic acid bacteria work together to prevent Candida infection
- 新一代云原生数据库的设计与实践
- CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
- Lack of comparator, operational amplifier to save the field! (the op amp is recorded as a comparator circuit)
猜你喜欢

What legal risks and qualifications should be paid attention to when building a digital collection platform?
![[paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba](/img/fa/f2d24ee3dbbbe6332c84a82109338e.png)
[paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba

Matplotlib数据可视化基础

Design and practice of new generation cloud native database

CCNP Part XII BGP (IV)

数字藏品市场新局面

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

The Lantern Festival is held on the fifteenth day of the first month, and the Lantern Festival begins to celebrate the reunion

新一代云原生数据库的设计与实践

CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
随机推荐
A new round of popularity of digital collections opens
北汽蓝谷:业绩承压,极狐难期
【邂逅Django】——(二)数据库配置
基金国际化的发展概况
在通达信上买基金安全吗?
Is the securities account opened by Yixue school for individuals safe? Is there a routine
bash: ln: command not found
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Crawler (2) - requests (1) | deep parsing of requests module
SQL Server列一相同的情况下,如何取列二的最大值,并重新生成表
678. 有效的括号字符串
华为HMS Core携手超图为三维GIS注入新动能
NC | intestinal cells and lactic acid bacteria work together to prevent Candida infection
678. Valid bracket string
基于Matlab的开环Buck降压斩波电路Simulink仿真电路模型搭建
Valgrind usage of memory leak locating tool
Kotlin coprocessor scheduling switch threads it's time to unravel the truth
Is it safe to open a stock account online in 2022? Is there any danger?
投稿开奖丨轻量应用服务器征文活动(5月)奖励公布
bash: ln: command not found