方法一:创建一模一样的表结构(包括索引,不包括表中数据)
mysql> desc t_my_series; +-------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+----------------+ | ID | bigint(20) | NO | PRI | NULL | auto_increment | | CREATE_TIME | datetime | YES | | NULL | | | UPDATE_TIME | datetime | YES | | NULL | | | APP_USER_ID | bigint(20) | YES | MUL | NULL | | | SERIES_ID | bigint(20) | YES | MUL | NULL | | +-------------+------------+------+-----+---------+----------------+ 5 rows in set (0.03 sec) mysql> create table t_my_series_new like t_my_series; Query OK, 0 rows affected (0.04 sec) mysql> desc t_my_series_new; +-------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+----------------+ | ID | bigint(20) | NO | PRI | NULL | auto_increment | | CREATE_TIME | datetime | YES | | NULL | | | UPDATE_TIME | datetime | YES | | NULL | | | APP_USER_ID | bigint(20) | YES | MUL | NULL | | | SERIES_ID | bigint(20) | YES | MUL | NULL | | +-------------+------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
方法2:创建一模一样的表结构(不包括索引,不包括表中数据)
mysql> create table t_my_series_new select * from t_my_series limit 0; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc t_my_series_new ; +-------------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+-------+ | ID | bigint(20) | NO | | 0 | | | CREATE_TIME | datetime | YES | | NULL | | | UPDATE_TIME | datetime | YES | | NULL | | | APP_USER_ID | bigint(20) | YES | | NULL | | | SERIES_ID | bigint(20) | YES | | NULL | | +-------------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
方法3:通过分别备份表结构和表数据,然后rename原表,导入备份的表结构和表数据恢复原表的方式!(包括索引,包括表中数据!)
#备份t_my_series表结构和数据 $MYSQLDUMP rrmj t_my_series -d >t_my_series.frm $MYSQLDUMP rrmj t_my_series -t >t_my_series.data #rename表t_my_series为t_my_series_bak $MYSQL -e "use rrmj;rename table t_my_series to t_my_series_bak;" #导入t_my_series表结构和数据,恢复t_my_series表 $MYSQL rrmj < t_my_series.frm $MYSQL rrmj < t_my_series.data
转载于:https://blog.51cto.com/watchman110/1690546