Created
May 26, 2019 03:31
-
-
Save pfernandez/80cf8d41a134017e076bac72fd097d48 to your computer and use it in GitHub Desktop.
Replace table name prefixes in a mysqldump file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Replace table name prefixes in a mysqldump file. Test first! | |
dumpfile=~/my-database.sql | |
backup=$dumpfile.$(date +%F_%T).orig | |
oldprefix= | |
newprefix=staging_ | |
echo "Backing up $dumpfile to $backup..." | |
cp $dumpfile $backup | |
echo "Applying new prefix '$newprefix'..." | |
sed -i " | |
s/DROP TABLE IF EXISTS \`${oldprefix}/DROP TABLE IF EXISTS \`${newprefix}/ | |
s/CREATE TABLE \`${oldprefix}/CREATE TABLE \`${newprefix}/ | |
s/ALTER TABLE \`${oldprefix}/ALTER TABLE \`${newprefix}/ | |
s/LOCK TABLES \`${oldprefix}/LOCK TABLES \`${newprefix}/ | |
s/INSERT INTO \`${oldprefix}/INSERT INTO \`${newprefix}/ | |
s/-- Table structure for table \`${oldprefix}/-- Table structure for table \`${newprefix}/ | |
s/-- Dumping data for table \`${oldprefix}/-- Dumping data for table \`${newprefix}/ | |
" $dumpfile | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment