How to Duplicate a MySQL Table with Data and Indices?
Nov 30, 2024 am 07:29 AMDuplicating MySQL Table: Data, Indices, and Structure
Question:
How can a MySQL table, including its indices and data, be replicated or duplicated to create a new table?
Answer:
To create an exact duplicate of a MySQL table, including its data, structure, and indices, follow these steps:
-
Create a new table with the same structure and indices as the original:
- CREATE TABLE new_table LIKE old_table;
-
Insert data from the old table into the new table:
- INSERT INTO new_table SELECT * FROM old_table;
Additional Options:
-
To copy only the structure and data without the indices, use the following query:
- CREATE TABLE new_table AS SELECT * FROM old_table;
-
To copy the indices and triggers along with the data, execute the following queries:
- CREATE TABLE new_table LIKE old_table;
- INSERT INTO new_table SELECT * FROM old_table;
The above is the detailed content of How to Duplicate a MySQL Table with Data and Indices?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I configure SSL/TLS encryption for MySQL connections?
