Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL flush tables - Current database or every database?

Tags:

mysql

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.

like image 332
Richard Avatar asked Dec 03 '08 12:12

Richard


People also ask

What does MySQL flush tables do?

The idea of FLUSH TABLES is to force all tables to be closed. This is mainly to ensure that if someone adds a new table outside of MySQL (for example, by copying files into a database directory with cp ), all threads will start using the new table.

How do I flush a MySQL database?

when we grant some privileges for a user, running the command flush privileges will reloads the grant tables in the mysql database enabling the changes to take effect without reloading or restarting mysql service. mysql> FLUSH TABLES; The command closes all tables which are currently open or in use.

What does flush do database?

Writing a buffer to disk is called buffer flushing . When a user thread modifies data in a buffer, it marks the buffer as dirty . When the database server flushes the buffer to disk, it subsequently marks the buffer as not dirty and allows the data in the buffer to be overwritten.

What is flush tables with read lock?

FLUSH TABLES WITH READ LOCK is useful if you want to take a backup of some tables. When FLUSH TABLES WITH READ LOCK returns, all write access to tables are blocked and all tables are marked as 'properly closed' on disk. The tables can still be used for read operations.


2 Answers

It's all databases.

like image 103
Brent Avatar answered Sep 22 '22 01:09

Brent


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.

like image 23
Bill Karwin Avatar answered Sep 23 '22 01:09

Bill Karwin