3 ways I know of MySQL quick build table

Source: Internet
Author: User
Tags mul

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.