假设现在有表books:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
1.复制表结构文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
1.1 含有主键等信息的完整表结构文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
CREATE table 新表名 LIKE book;
1.2 只有表结构,没有主键等信息文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
create table 新表名 select * from books; 或 create table 新表名 as (select * from book); 或 create table 新表名 select * from books where 1=2;
2.将旧表中的数据灌入新表文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
INSERT INTO 新表 SELECT * FROM 旧表;
注:新表必须已经存在文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
3.输入创建表的DDL语句文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
show create table 表名;
4.清空表数据文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
truncate table 表名;
5.备份数据库文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
比如备份library数据库文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
进去Mysql的bin目录文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
C:\Program Files\MySQL\MySQL Server 5.5\bin> 利用“mysqldump -u 用户名 -p 数据库名 >备份名字”导出数据库到文件 C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump -u root -p library >library.sql Enter password: ***
即可.文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
6.还原数据库文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
还原library数据库为例文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
先create database library文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
然后 下mysql>下文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
输入“source 路径”文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html
即可。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/19902.html