Change MySQL database name in SQL file I have a 2GB mysql backup file that has several databases in it and would like to change the name for one of the databases. What approaches  can I use to tackle this issue ? I have used sed but it ends up making changes where it should not.

sed 's/CREATE DATABASE \/*!32312 IF NOT EXISTS*\/ `mydb`/`mydb2`/g' all_databases.sql &gt; out.sql
Why do you want to complicate it?

1). vi the backup.sql file. 

2). /mydb -&gt; find for line 'mydb'

3). For sure the first two line will be this.



 CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mydb` ;
    use `mydb`;

4). Just change mydb from both the lines to mydb2 and save the file
and import it.