patternsqlMinor
Use mysqldump to backup table with a new table name
Viewed 0 times
newwithmysqldumpnameusetablebackup
Problem
Is there a way to back up a table using
So that If I back up the table 'test_table' like so.
and I want 'test_table' to now be called 'test_table_backup' in the
I know i can just dump the file then craft some way to do a search and replace on the table name but I was hoping there was a safer way using mysqldump itself.
mysqldump so the table that is being backed up can have a new name in the sql script created by mysqldump.So that If I back up the table 'test_table' like so.
mysqldump -u user -p db_name test_table > backup.sqland I want 'test_table' to now be called 'test_table_backup' in the
backup.sql that is created. CREATE TABLE `test_table_backup` (
...
);I know i can just dump the file then craft some way to do a search and replace on the table name but I was hoping there was a safer way using mysqldump itself.
Solution
You have to use sed to transform the table name
Give it a Try !!!
mysqldump -u user -p db_name test_table | sed 's/test_table/test_table_backup/g' > backup.sqlGive it a Try !!!
Code Snippets
mysqldump -u user -p db_name test_table | sed 's/test_table/test_table_backup/g' > backup.sqlContext
StackExchange Database Administrators Q#76011, answer score: 3
Revisions (0)
No revisions yet.