generating database with different name from mysqldump backup

Sure, when you import it you do this right:

mysql -uuser -ppassword databasename < mydump.sql

You can put anything you want where I wrote databasename - as long as that database actually exists :)


This depends on how you created your MySQL dB dump file

for example, if you do

mysqldump -h localhost -u user mydb -pXXX > mydb.sql

There won't be any CREATE DATABASE statements in your sql dump file. But I think you can only backup one database.

If you create your mysql dump file with --database or --all-databases option for example

mysqldump -h localhost -u user --database mydb -pXXX > mydb.sql 
mysqldump -h localhost -u user --all-databases -pXXX > alldb.sql

then you will see CREATE DATABASE statement in your mysql dump file. If you want a different dB name, you will need to change it before DB restore.


If the name of the database is include the SQL file, I didn't find any other way than modify the SQL file.

My favorite command to do it :

    sed -i "s/\`old_db_name\`/\`new_db_name\`/g" my_sql_file.sql