to get an idea of how to test this, do an export with "mysqldump user/password -opt --all-databases > db_create.sql". This tools generates a script to recreate the database. It also includes "if exist" statements, to do a drop if necessary.
I hope this will give you the needed statements.
The actual db names are listed with "show databases".