当前位置:网站首页>MySQL复制表结构、表数据的方法
MySQL复制表结构、表数据的方法
2022-07-30 19:30:00 【asdfadafd】
1、复制表结构及数据到新表
create table new_table_name select * from old_table_name;
这种方法的一个最不好的地方就是新表中没有了旧表的primary key、Extra(auto_increment)等属性。
2、只复制表结构到新表
create table new_table_name select * from old_table_name where 1=2;
或
create table new_table_name like old_table_name;
3、复制旧表的数据到新表(假设两个表结构一样)
insert into new_table_name select * from old_table_name;
4、复制旧表的数据到新表(假设两个表结构不一样)
insert into new_table_name(字段1,字段2,字段3) select (字段1,字段2,字段3) from old_table_name;
5、表不在同一数据库中(如:db1 table1,db2 table2)
完全复制
insert into db1.table1 select * from db2.table2;
不复制重复记录
insert into db1.table1 select distinct* from db2.table2;
复制前10条记录
insert into db1.table1 select 10* from db2.table2;
6、查看表的创建SQL
show create table table_name;
这样会将表的创建SQL列出。我们只需要将该SQL拷贝出来,更改table_name,就可以创建一个完全一样的表。
7、清除表数据
delete from table_name;
或
truncate table table_name;
不带where参数的delete语句可以删除mysql表中所有内容;
使用truncate table也可以清空mysql表中所有内容。
但是使用delete清空表中的记录,内容的ID仍然从删除点的ID继续建立,而不是从1开始。
而truncate相当于保留了表的结构而重新建立了一张同样的新表。
效率上truncate比delete快。
但truncate删除后不记录mysql日志,不可以恢复数据。
delete的效果有点像将mysql表中所有记录一条一条删除到删完。
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Entering the applet for the first time
- 数据库索引:索引并不是万能药
- MindSpore:【语音识别】DFCNN网络训练loss不收敛
- What is the difference between a cloud database and an on-premises database?
- ImportError:attempted relative import with no known parent package
- MindSpore: CV.Rescale(rescale,shift)中参数rescale和shift的含义?
- LocalDate时间生成
- Is the iPhone really thirteen incense?The two generations of products are completely compared, perhaps the previous generation is more worth buying
- MySQL分组后取最大一条数据【最优解】
- MySQL数据库主从配置
猜你喜欢
【PyTorchVideo教程01】快速实现视频动作识别
Download Win11 how to change the default path?Download Win11 change the default path method
iPhone真是十三香?两代产品完全对比,或许上一代更值得买
MindSpore: CV.Rescale(rescale,shift)中参数rescale和shift的含义?
The JDBC programming of the MySQL database
SimpleOSS third-party library libcurl and engine libcurl error solution
MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
OneFlow source code analysis: Op, Kernel and interpreter
MySQL database - DQL data query language
LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search
随机推荐
Object和Map的区别
又一家公司面试的内容
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
云数据库和本地数据库有什么区别?
第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结
MySQl数据库————DQL数据查询语言
coming!Dongfang Selection brings goods to the live broadcast of Longjiang agricultural products
MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
The problem of writing go run in crontab does not execute
MindSpore:【Resolve node failed】解析节点失败的问题
linux下mysql8安装
试写C语言三子棋
【科普】无线电波怎样传送信息?
[flink] Error finishing Could not instantiate the executor. Make sure a planner module is on the classpath
解决终极bug,项目最终能顺利部署上线。
【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
MySQL database - DQL data query language
Entering the applet for the first time
MySQL数据库————视图和索引
【Node实现数据加密】