ensure calling mysql_thread_init() and mysql_thread_exit() when necessary