Leilin Peng Share: MySQL replication table

  If we need a complete copy of MySQL data tables, including the table structure, indexes, defaults and so on. If you only use the CREATE TABLE ... SELECT command, can not be achieved.

  This chapter will introduce how to complete copy MySQL data tables, the following steps:

  Use SHOW CREATE TABLE command to get the data table is created (CREATE TABLE) statement that contains the original data table structure, indexes and so on.

  Copy the following command to display the SQL statement, modify the table name, and execute SQL statements, the above command will complete copy data table structure.

  If you want to copy the contents of the table, you can use INSERT INTO ... SELECT statement to achieve.

  Examples

  Try the following instances replicate table codercto_tbl.

  step one:

  For a complete structure of the data table.

  mysql> SHOW CREATE TABLE codercto_tbl \G;

  *************************** 1. row ***************************

  Table: codercto_tbl

  Create Table: CREATE TABLE `codercto_tbl` (

  `codercto_id` int(11) NOT NULL auto_increment,

  `codercto_title` varchar(100) NOT NULL default '',

  `codercto_author` varchar(40) NOT NULL default '',

  `submission_date` date default NULL,

  PRIMARY KEY (`codercto_id`),

  UNIQUE KEY `AUTHOR_INDEX` (`codercto_author`)

  ) ENGINE=InnoDB

  1 row in set (0.00 sec)

  ERROR:

  No query specified

  Step two:

  Modify data table name SQL statements and execute SQL statements.

  mysql> CREATE TABLE `clone_tbl` (

  -> `codercto_id` int(11) NOT NULL auto_increment,

  -> `codercto_title` varchar(100) NOT NULL default '',

  -> `codercto_author` varchar(40) NOT NULL default '',

  -> `submission_date` date default NULL,

  -> PRIMARY KEY (`codercto_id`),

  -> UNIQUE KEY `AUTHOR_INDEX` (`codercto_author`)

  -> ) ENGINE=InnoDB;

  Query OK, 0 rows affected (1.80 sec)

  Step three:

  After the second step, you will create a new cloned clone_tbl table in the database. If you want to copy the data table you can use INSERT INTO ... SELECT statement to achieve.

  mysql> INSERT INTO clone_tbl (codercto_id,

  -> codercto_title,

  -> codercto_author,

  -> submission_date)

  -> SELECT codercto_id,codercto_title,

  -> codercto_author,submission_date

  -> FROM codercto_tbl;

  Query OK, 3 rows affected (0.07 sec)

  Records: 3 Duplicates: 0 Warnings: 0

  After performing the above steps, you will complete the copy table, including the table structure and table data.

  Click to see all MySQL Tutorial Articles: https://www.codercto.com/courses/l/30.html

  (Editor: Leilin Peng Source: network intrusion deleted)

Guess you like

Origin www.cnblogs.com/pengpeng1208/p/11040007.html