HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Use mysqldump to backup table with a new table name

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
newwithmysqldumpnameusetablebackup

Problem

Is there a way to back up a table using 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.sql


and 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

mysqldump -u user -p db_name test_table | sed 's/test_table/test_table_backup/g' > backup.sql


Give it a Try !!!

Code Snippets

mysqldump -u user -p db_name test_table | sed 's/test_table/test_table_backup/g' > backup.sql

Context

StackExchange Database Administrators Q#76011, answer score: 3

Revisions (0)

No revisions yet.