Question: I have a serious performance issue about mysql.  

The storage engine is myisam.  

I find such pattern in slow log:  

if the update command is slow, a `use database_name` will be in front of it, and the lock time will be long.

does use database\_name command lock the whole database? will database\_name command flush the cache and then has bad effects in update command?

Answer: 
No, the use database command does not have a great cost.

But the UPDATE statement locks the whole table if you use MyISAM. You're probably seeing multiple UPDATE statements queuing up against each other.

I recommend using InnoDB for all tables. Not only for its support for row-level locking (actually MVCC which is better than row-level locking), but also InnoDB is superior to MyISAM in terms of resistance against data corruption.
`use database` does *not* lock the database. It simply provides a default database to reference in future queries.