We're running into issues where we need to work on recovering some lost data (yay improper use of maatkit on a master-to-master replication setup), and I'm trying to import an old dump of the database. The problem is that at the top of the file, it's explicitly specifying the database (mysqldump was run with the --all-databases option), and I need to change that DB to something else so I can get another in there alongside it for comparison. The line reads:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `dms` /*40100 DEFAULT CHARACTER SET latin1 */
I've been unsuccessful at opening the file in vi to edit due to the large size of the dump, and am a little hesitant to use sed because of how it's going to read line-by-line for any pattern matching. What is the easiest and most efficient way to change the above line in the sql dump to read:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `dms_old` /*40100 DEFAULT CHARACTER SET latin1 */
Or simply use some mysql black magic to import it into database dms_old
?
sed
should have no problems with that. Just do:
`sed '/CREATE DATABASE/s/dms/dms_old/'`
with appropriate redirections.
I think this is right.
sed '0,/dms/s/dms/dms_old/' dump.sql
That will only run the replacement once, and only for the first line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With