当前位置:网站首页>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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Download Win11 how to change the default path?Download Win11 change the default path method
- - daily a LeetCode 】 【 191. A number of 1
- Zabbix 5.0 Monitoring Tutorial (1)
- Witness the magical awakening of the mini world in HUAWEI CLOUD
- 【MindSpore】多卡训练保存权重问题
- 牛客刷题系列之进阶版(搜索旋转排序数组,链表内指定区间反转)
- Linux下最新版MySQL 8.0的下载与安装(详细步骤)
- The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
- MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
- Perfectly Clear QuickDesk & QuickServer图像校正优化工具
猜你喜欢

第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结

【网站放大镜效果】两种方式实现

MySQL数据库之JDBC编程

Swiper rotates pictures and plays background music

The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)

Google's AlphaFold claims to have predicted almost every protein structure on Earth

Delay queue optimization (2)

MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远

MySQL数据库 ---MySQL表的增删改查(进阶)

云数据库和本地数据库有什么区别?
随机推荐
【网站放大镜效果】两种方式实现
MindSpore:ImageFolderDataset数据读取问题
Vulkan开启特征(feature)的正确姿势
055 c# print
What is a RESTful API?
LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集
MySQL数据库主从配置
Entering the applet for the first time
What is the value of biomedical papers? How to translate the papers into Chinese and English?
【科普】无线电波怎样传送信息?
7.30模拟赛总结
055 c# print
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
解决终极bug,项目最终能顺利部署上线。
SimpleOSS第三方库libcurl与引擎libcurl错误解决方法
MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
JsonUtil基于字符串操作josn
MindSpore:mindspore有没有类似tf.GradientTape()用来求解梯度的?
[PyTorchVideo Tutorial 01] Quickly implement video action recognition