4.2.28. MySQL copy table

发布时间 : 2025-10-25 13:32:49 UTC      

Page Views: 9 views

If we need to completely copy the MySQL data table, including the table structure, index, default value, etc. If you only use the CREATE TABLE … SELECT Commands cannot be realized.

This section will show you how to copy the MySQL data table completely. The steps are as follows:

  • Use SHOW CREATE TABLE Command to get the create data table ( CREATE TABLE Statement, which contains the structure of the original data table, index, and so on.

  • Copy the SQL statement shown in the following command, modify the datasheet name, and execute the SQL statement, which will completely copy the datasheet structure.

  • If you want to copy the contents of the table, you can use the INSERT INTO … SELECT Statement to implement.

Example

Try the following example to copy the table runoob_tbl.

步骤一:

Gets the complete structure of the data table.

mysql> SHOW CREATE TABLE runoob_tbl \G; *************************** 1. row *************************** Table: runoob_tbl Create Table: CREATE TABLE `runoob_tbl` ( `runoob_id` int(11) NOT NULL auto_increment, `runoob_title` varchar(100) NOT NULL default '', `runoob_author` varchar(40) NOT NULL default '', `submission_date` date default NULL, PRIMARY KEY (`runoob_id`), UNIQUE KEY `AUTHOR_INDEX` (`runoob_author`) ) ENGINE=InnoDB 1 row in set (0.00 sec) ERROR: No query specified 

步骤二:

Modify the data table name of the SQL statement and execute the SQL statement.

mysql> CREATE TABLE `clone_tbl` ( -> `runoob_id` int(11) NOT NULL auto_increment, -> `runoob_title` varchar(100) NOT NULL default '', -> `runoob_author` varchar(40) NOT NULL default '', -> `submission_date` date default NULL, -> PRIMARY KEY (`runoob_id`), -> UNIQUE KEY `AUTHOR_INDEX` (`runoob_author`) -> ) ENGINE=InnoDB; Query OK, 0 rows affected (1.80 sec) 

步骤三:

After performing the second step, you will create a new clone table clone_tbl in the database. If you want to copy the data from the data table, you can use the INSERT INTO… SELECT Statement to implement.

mysql> INSERT INTO clone_tbl (runoob_id, -> runoob_title, -> runoob_author, -> submission_date) -> SELECT runoob_id,runoob_title, -> runoob_author,submission_date -> FROM runoob_tbl; Query OK, 3 rows affected (0.07 sec) Records: 3 Duplicates: 0 Warnings: 0 

After performing the above steps, the contents of the table are fully copied, including the table structure and table data.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。