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.
No the command neither locks the database nor flushes, it simply makes it easier to reference one database when there are many to choose from. You may want to take a look at the [documentation](http://dev.mysql.com/doc/refman/5.0/en/use.html).

If you are having slow query times, perhaps take a look to see if you are doing any intensive updates to the database as MyISAM does lock the table (rather than the row, like InnoDB) on updates.