Once login there is no way to connect to another database. The only way out is we have to export the data first and then import
Use the mysqldump tool for exporting like:
mysqldump -h HOST -u USER -p database table > export.sql
Then import it via:
mysql -h HOST -u USER -p database table < export.sql