Method One: Create an identical table structure (including indexes, excluding data in the table)
mysql> desc t_my_series;+-------------+------------+------+-----+---------+----------------+| field | type | Null | Key | Default | Extra |+-------------+------------+------+-----+---------+----------------+| id | bigint ( | NO   | PRI) | null | auto_increment | | create_time | datetime | yes | | NULL | | | update_time | datetime | yes | | null | | | app_user_id | bigint ( | YES | MUL | NULL ) | | | series_id | bigint ( | 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 ( | NO ) | pri | null | auto_increment | | create_time | datetime | yes | | NULL | | | update_time | datetime | yes | | NULL | | | app_user_id | bigint ( | YES  | MUL | NULL &NBS)p; | | | series_id | bigint ( | yes | mul | null) | |+-------------+------------+------+-----+---------+----------------+5 rows in set (0.00 SEC)
Method 2: Create a table structure that is identical (excluding indexes, excluding data in tables)
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: 0mysql> desc t_my_series_new ;+-------------+------------+------ +-----+---------+-------+| field | type | null | key | default | extra |+------------- +------------+------+-----+---------+-------+| id | bigint ( | NO | | 0 ) | | | create_time | datetime | yes | | null | | | update_time | datetime | yes | | null | | | app_user_id | bigint ( | yes | | null) | | | series_id | bigint ( | yes | |) null | |+-------------+------------+---- --+-----+---------+-------+
5 rows in Set (0.00 sec)
Method 3: By backing up the table structure and table data separately, then rename the original table, import the backup table structure and table data to restore the original table way! (including the index, including the data in the table!) )
#备份t_my_series表结构和数据 $MYSQLDUMP rrmj t_my_series-d >t_my_series.frm$mysqldump rrmj t_my_series-t >t_my_ Series.data#rename table t_my_series for t_my_series_bak$mysql-e "Use Rrmj;rename table T_my_series to T_my_series_bak;" #导入t_my_series表结构和数据, recover t_my_series table $mysql RRMJ < T_my_series.frm$mysql RRMJ < T_my_series.data
This article is from the "time to cook the Rain" blog, please be sure to keep this source http://watchman110.blog.51cto.com/9194028/1690546
3 ways I know of MySQL quick build table