How do I get a new database connection with a new setting? I want to set the GLOBAL variable innodb_flush_log_at_trx_commit, and then run a migration after getting a new connection since changes to a global variable does not affect the current session.

So the raw mysql would go like this...

-- set the variable that speeds my migrate up by 40x
SET GLOBAL innodb_flush_log_at_trx_commit=0;
-- reconnect (starts a new mysql db session)
connect;

-- Do the import

-- at the end of the import
SET GLOBAL innodb_flush_log_at_trx_commit=1;
connect;


I've not tried anything yet, but I'm interested to see if anyone else has looked at this, and the issues encountered, and the end solution.
I like your gutsy move in this regard.
I wrote about changing innodb_flush_log_at_trx_commit in the DBA StackExchange

Feb 10, 2012 : Is it safe to use innodb_flush_log_at_trx_commit = 2
Mar 08, 2012 : What are some key configuration settings for using an InnoDb table for session storage?
Dec 07, 2012 : Dynamic change to innodb_flush_log_at_trx_commit

I also wrote about tuning InnoDB for better INSERT performance

Jul 04, 2012 : Capabilities of InnoDB INSERT Performance

EPILOGUE
You have the right idea. You should experiment with this on a Staging DB Server (load data, test drive the setting, kick the tires)
Note the difference between setting innodb_flush_log_at_trx_commit to 0 and 2

Setting to 0 : any mysqld process crash can erase the last second of transactions. The log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but no writes are done at a transaction commit.
Setting to 2 : only an operating system crash or a power outage can erase the last second of transactions. The log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. Before MySQL 5.6.6, the flushing on the log file takes place once per second. Note that the once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues. As of MySQL 5.6.6, flushing frequency is is controlled by innodb_flush_log_at_timeout instead.

Based on this difference, you have to decide who do you trust flushing data, the Operating System or the mysqld process. Using 0 leans in favor of mysqld. Using 2 seems to be OS oriented.