当前位置:网站首页>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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
- 【flink】报错整理 Could not instantiate the executor. Make sure a planner module is on the classpath
- 又一家公司面试的内容
- Start foreground Activity
- DM8: Single database and single instance to build a local data guard service
- 【PyTorchVideo教程01】快速实现视频动作识别
- 【MindSpore】多卡训练保存权重问题
- Swiper rotates pictures and plays background music
- Range.CopyFromRecordset method (Excel)
- Spark学习:用spark实现ETL
猜你喜欢
![[PyTorchVideo Tutorial 01] Quickly implement video action recognition](/img/1a/696c5722bb94fabd688a8714ae2e8c.png)
[PyTorchVideo Tutorial 01] Quickly implement video action recognition

Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接

MongoDB打破了原则引入SQL?

【PyTorchVideo教程01】快速实现视频动作识别

Cesium加载离线地图和离线地形

NXP IMX8QXP replacement DDR model operation process

redis

【Node实现数据加密】

MindSpore: CV.Rescale(rescale,shift)中参数rescale和shift的含义?
![[Prometheus] An optimization record of the Prometheus federation [continued]](/img/5d/56e171b7a02584337a0cfe5c731fb2.png)
[Prometheus] An optimization record of the Prometheus federation [continued]
随机推荐
【MindSpore1.2.0-rc1产品】num_workers问题
The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
Is the iPhone really thirteen incense?The two generations of products are completely compared, perhaps the previous generation is more worth buying
VBA 连接Access数据库和Excle
【网站放大镜效果】两种方式实现
Entering the applet for the first time
自己需要努力
实体中增加操作方法
跨域问题的解决方法
coming!Dongfang Selection brings goods to the live broadcast of Longjiang agricultural products
MySQL分组后取最大一条数据【最优解】
The problem of writing go run in crontab does not execute
电脑死机的时候,发生了什么?
看完《二舅》,我更内耗了
Google's AlphaFold claims to have predicted almost every protein structure on Earth
MindSpore:【JupyterLab】查看数据时报错
LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集
nlohmann json 使用指南【visual studio 2022】
Scala学习:breakable
[TypeScript]编译配置