I want to do that using a code and not using a tool like \"MySQL Migration Toolkit\". The easiest way I know is to open a connection (using MySQL connectors) to DB1 and read
from http://dev.mysql.com/doc/refman/5.0/en/rename-table.html:
As long as two databases are on the same file system, you can use RENAME TABLE to move a table from one database to another:
RENAME TABLE current_db.tbl_name TO other_db.tbl_name;