I'm going to add that there is nothing wrong with the database name that is
in the query. If the same query, with slightly different constraints and
the _exact_ same database name, is run 1000 times and 3 of them give the
Unknown database error, that rules out an application error.
Furthermore,
Just starting using mysql. I am just guesing here :-).
It seems to me that it is looking for a database called
"databasename"? Perhaps somewhere in your application
you are asking the mysql about "databasename" database.
I mean, is it possible that you forgot to replace
"databasename" with the r