MySQL replication table detailed explanation If we need to completely copy the MySQL data table, including the table structure, indexes, default values, etc. This cannot be achieved using only the CREATE TABLE ... SELECT command. This section will introduce how to completely copy a MySQL data table. The steps are as follows:
Examples Try the following example to copy the table tutorials_tbl. Step 1: Get the complete structure of the data table. mysql> SHOW CREATE TABLE tutorials_tbl \G; *************************** 1. row *************************** Table: tutorials_tbl Create Table: CREATE TABLE `tutorials_tbl` ( `tutorial_id` int(11) NOT NULL auto_increment, `tutorial_title` varchar(100) NOT NULL default '', `tutorial_author` varchar(40) NOT NULL default '', `submission_date` date default NULL, PRIMARY KEY (`tutorial_id`), UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`) ) TYPE=MyISAM 1 row in set (0.00 sec) ERROR: No query specified Step 2: Modify the data table name of the SQL statement and execute the SQL statement. mysql> CREATE TABLE `clone_tbl` ( -> `tutorial_id` int(11) NOT NULL auto_increment, -> `tutorial_title` varchar(100) NOT NULL default '', -> `tutorial_author` varchar(40) NOT NULL default '', -> `submission_date` date default NULL, -> PRIMARY KEY (`tutorial_id`), -> UNIQUE KEY `AUTHOR_INDEX` (`tutorial_author`) -> ) TYPE=MyISAM; Query OK, 0 rows affected (1.80 sec) Step 3: After completing the second step, you will create a new clone table clone_tbl in the database. If you want to copy the data in a table you can use the INSERT INTO... SELECT statement to do so. mysql> INSERT INTO clone_tbl (tutorial_id, -> tutorial_title, -> tutorial_author, -> submission_date) -> SELECT tutorial_id,tutorial_title, -> tutorial_author,submission_date -> FROM tutorials_tbl; Query OK, 3 rows affected (0.07 sec) Records: 3 Duplicates: 0 Warnings: 0 After executing the above steps, you will completely copy the table, including the table structure and table data. Thank you for reading, I hope it can help you, thank you for your support of this site! You may also be interested in:
|
<<: The difference and use of json.stringify() and json.parse()
>>: Basic operation tutorial of files and permissions in centos
Three types of message boxes can be created in Ja...
When the height attribute of Text is defined, the ...
1. First, an error message is reported when assoc...
Background requirements: As the business grows la...
Hello everyone, I am Qiufeng. Recently, WeChat ha...
A colleague asked me what N and M mean in the MyS...
Nginx can generally be used for seven-layer load ...
When developing a website, you often need to use ...
In order to express the deep condolences of peopl...
Upgrade background: In order to solve the vulnera...
1. Nginx installation steps 1.1 Official website ...
This article example shares the specific code of ...
Table of contents output output.path output.publi...
Without further ado, I will post the code for you...
When we introduced nginx, we also used nginx to s...