How to create a copy of table in MySQL / MariaDB

mysql mariadb

MYSQL is a popular database server for production and development. MariaDB is a fork of MySQL to keep it independent from Oracle (new owner of MySQL). So they are almost the same If we don’t talk about internal implementations and optimizations.

Create a table with the same scheme:

CREATE TABLE {{ new table }} LIKE {{ old table }}; 

Fill new table with the same data:

INSERT {{ new table }} SELECT * FROM {{ old table }};

You can use it before you want to run a migration, which can damages your data. And the same commands for recovering, if migration breaks your data.