Duplicating a MySQL Table with Indices and Data
Replicating MySQL tables often requires preserving data, structure, and indices. Copying these components separately can be tedious. Fortunately, there's a straightforward method to achieve this.
To duplicate a table completely, execute the following steps:
CREATE TABLE new_table LIKE old_table;
INSERT INTO new_table SELECT * FROM old_table;
This method effectively copies all data, structure, and indices while avoiding extra table recreation and data duplication.
If copying only data and structure is desired, the following query can be used:
CREATE TABLE new_table AS SELECT * FROM old_table;
This query creates a new table with the same data and structure as the original table, but it does not copy any indices.
The above is the detailed content of How Can I Duplicate a MySQL Table Including Data and Indices?. For more information, please follow other related articles on the PHP Chinese website!