Search.Queue.MySQL: Protect against interleaving SQL queries.

The Mysql database connection object is not reentrant,
so if multiple threads attempt to use the same connection
object at the same time, it will likely cause the error
"Lost connection to MySQL server during query".

In this case the function num_with_stage() could be called
to present ststus information while the queue was in use.

This patch fixes the problem by using thread local connections.

It also survives the database connection having gone stale.