Copying tables in MySQL can mean duplicating structure, data, or both. Common approaches: CREATE TABLE ... AS SELECT to create-and-copy, and INSERT INTO ... SELECT to copy into an existing table.
// Copy structure + data into new_table
CREATE TABLE new_table AS
SELECT * FROM old_table;
// Copy only structure (no rows)
CREATE TABLE new_table AS
SELECT * FROM old_table WHERE 1=0;
// Copy data into an existing table
INSERT INTO new_table
SELECT * FROM old_table;
// Copy specific columns into a new table
CREATE TABLE new_table AS
SELECT id, name FROM old_table;
// Create original Employees table and insert sample rows
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Salary DECIMAL(10,2)
);
// Insert sample rows
INSERT INTO Employees VALUES (1,'Alice',5000.00),(2,'Bob',6000.00);
// Copy structure + data into a new backup table
CREATE TABLE Employees_Backup AS
SELECT * FROM Employees;
// Copy structure only into a new table (no data)
CREATE TABLE Employees_Structure AS
SELECT * FROM Employees WHERE 1=0;
// Copy only rows matching condition
CREATE TABLE HighSalaryEmployees AS
SELECT * FROM Employees WHERE Salary > 5500;
// Insert rows into existing table (append)
INSERT INTO Employees_Backup
SELECT * FROM Employees;
WHERE 1=0 returns no rows, copying only columns.SHOW CREATE TABLE to replicate them manually.SHOW CREATE TABLE table_name; to obtain full DDL including indexes.WHERE filters to reduce load and space usage.CREATE TABLE ... AS SELECT.SHOW CREATE TABLE on the original table, recreate indexes on the backup, then compare performance.