Sep 25 2008

how to backup a mysql table

Category: SQL, Snippetslotsofcode @ 8:18 am

A nice and simple way of backing up a mysql table without renaming / exporting is to create a new table with the same structure and copy across the data for the current table.

This can be done without having to copy and paste the structure of the table.

Simply replace the [NEW_TABLE] and [OLD_TABLE] markers with your new / old table names.

CREATE TABLE [NEW_TABLE] LIKE [OLD_TABLE];
INSERT INTO [NEW_TABLE] SELECT * FROM [OLD_TABLE];

For example.

CREATE TABLE products_backup LIKE products;
INSERT INTO products_backup SELECT * FROM products;

This will create the table and maintain any indexes / keys.

I hope this helps.

Leave a Reply

 
 
Please enter the word above into the box below, the word is not case sensitive.
 
If you have trouble reading the word above then click here to load a new word.
Security word:



Powered by WordPress - Created by Tommaso Baldovino

-->
Comments   Web Developer
Firefox   Google Chrome