Set these as follows in my.cnf (takes effect after mysqld is restarted):
If you do not want to restart mysql, then run these two commands:
SET GLOBAL interactive_timeout = 180;
SET GLOBAL wait_timeout = 180;
This will not close the connections already open. This will cause new connections to close in 180 seconds.