tags:

views:

5091

answers:

3

Does the MySQL command :

FLUSH TABLES;

flush every table in the current database, or every table on the server ?

I'm using MySQL 5.0 - the documentation is unclear, although it does mention that :

FLUSH TABLES WITH READ LOCK;

will do so for ALL databases.

Thanks.

+2  A: 

I tried to look this up but I couldn't find an authoritative answer either.

  • I looked in the manual, as you did.
  • I found the MySQL Internals documentation on FLUSH TABLES, but it doesn't say specifically.
  • I even read the source code in mysql_server/sql/sql_base.cc but couldn't find the answer quickly.

I assume the answer is one of those things that the developers feel is so obvious that they never need to say it.

According to the internals doc, the MySQL table cache holds a list of of most recently used tables. There is no mention of database-specific table caches, there seems to be only one table cache in the MySQL Server.

FLUSH TABLES is described as forcing all open tables (those in the table cache) to be closed. There is no mention of this being limited to one database, but you can specify individual tables in the arguments to FLUSH TABLES. So likewise, I assume this applies to the whole table cache by default, and therefore to all databases with open files on the MySQL Server.

Bill Karwin
+3  A: 

It's all databases.

UltimateBrent
Citation Needed. How do you know?
Oddthinking
I've done it before...
UltimateBrent
+2  A: 

when you do just a mysql_connect and then "show tables" for example -> mysql_error(): No Database selected

with "flush tables" there is no mysql_error, so i think the answer is every database