当前位置:网站首页>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
边栏推荐
- leetcode:111. Minimum depth of binary tree
- 零基础入行软件测试必看,10年测试老鸟的良心建议(共15条)
- Japanese professor sues Intel FPGA and SOC products for infringing a design patent
- Recommend a JSON visualization tool artifact!
- 在通达信上买基金安全吗?
- Handling distributed transactions with powerful dbpack (PHP tutorial)
- 中国探月工程独家藏品限量发售!
- [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
- Valgrind usage of memory leak locating tool
- Rising stars in Plant Sciences (rsps2022) final Science Lecture (6.30 pm)
猜你喜欢

Who's still buying three squirrels

数字藏品市场新局面

缺少比较器,运放来救场!(运放当做比较器电路记录)

商城小程序源码开源版-可二开

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

venv: venv 的目录结构

中国探月工程独家藏品限量发售!

Kotlin coprocessor scheduling switch threads it's time to unravel the truth

【邂逅Django】——(二)数据库配置

The list of winners of the digital collection of "century master" was announced
随机推荐
12款大家都在用的產品管理平臺
SQL SERVER2014删除数据库失败,报错偏移量0x0000...
dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
Prefabricated dishes usher in the "golden age", who can lead the next trillion market
C one line code calculates the MD5 value of the file - codeplus series
bash: ln: command not found
【Matytype】在CSDN博客中插入Mathtype行间与行内公式
客户端如何请求数据库?
The exclusive collection of China lunar exploration project is limited to sale!
Recommend a JSON visualization tool artifact!
Can I choose to open an account on CICC securities? Is it safe?
Half of 2022 has passed, isn't it sudden?
SQL optimization - in and not in, exist
CRC check
亿学学堂帮个人开的证券账户安全吗?是不是有套路
Crawler (2) - requests (1) | deep parsing of requests module
Today in history: the semiconductor war in the late 1990s; Von Neumann published the first draft; CBS acquires CNET
442. 数组中重复的数据
bash: ln: command not found
Uncover the secrets of new products! Yadi Guanneng 3 multi product matrix to meet the travel needs of global users