Thanks tachyon - the new settings have fixed the problem. I'm not sure which one, I haven't played with the new settings, but I think it may have been the query_cache_size, as all queries that are run more than once run faster, also from the mysql prompt.
Still the issue remains for a query that will take longer than the prescribed 30 seconds, but whatever.
Thanks again for helping.