Tip: MYSQL - Backup and re-index a table in your database

Print an Expertek Tip: MYSQL - Backup and re-index a table in your database

Backup your MySQL database table prior to re-indexing it


© Author: Neil Patterson -- 1/11/2022 6:10 pm - Views: 1905

Here's how:
Shore up your database primary keys.

CREATE TABLE table2 LIKE table1; //create a new table, copying structure from previous

INSERT INTO table2 SELECT * FROM table1 ORDER BY name; //Copy the data - the Primary key handles the autoincrements

RENAME TABLE table1 TO table1_Backup; //Copy the Old data to a new name as your backup

RENAME TABLE table2 TO table1; //Put the new data in place

- All Rights Reserved. Feel free to print with this footer and share it personally with your friends. Commercial reprint available, with permission.