You can duplicate a table in MySQL or MariaDB by creating a new table with the same structure as the source table and then copying the data or rows of the source table to the new table.

You can clone or create a copy of an existing MySQL / MariaDB table manually or you could use some dedicated SQL statements to simplify the process.

Steps to copy MySQL / MariaDB table:

  1. Log in to MySQL / MariaDB.
  2. Select the database of the source table.
    use mydatabase;
  3. Create a table with same structure as the source / existing table.
    CREATE TABLE new_table LIKE source_table;

    This will just create a new, empty table and does not copy the followings;

    • Foreign key definitions
    • DATA DIRECTORY
    • INDEX DIRECTORY
    • Data
  4. Copy the data from the source table using SELECT and INSERT statement after the new table is created.
    INSERT INTO new_table SELECT * FROM source_table;
Discuss the article:

Comment anonymously. Login not required.

Share!