Backup your MySQL database table prior to re-indexing it
Author: Neil Patterson ::
2024 Expertek
Views: 1904 - Updated 1/11/2022 6:10 pm Print this tip
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
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
Back to the TechTips Index | Internet Index
Did you enjoy "MYSQL - Backup and re-index a table in your database"??
If you Liked it, SHARE IT!
Ask a question, or Leave a comment below!