Change MySQL database name in SQL file
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.