MySQL 刷新表 - 当前数据库还是每个数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/336946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:28:12  来源:igfitidea点击:

MySQL flush tables - Current database or every database?

mysql

提问by Richard

Does the MySQL command :

MySQL命令是否:

FLUSH TABLES;

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

刷新当前数据库中的每个表,或服务器上的每个表?

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

我正在使用 MySQL 5.0 - 文档不清楚,尽管它确实提到:

FLUSH TABLES WITH READ LOCK;

will do so for ALL databases.

将对所有数据库都这样做。

Thanks.

谢谢。

回答by Brent

It's all databases.

都是数据库。

回答by Bill Karwin

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.ccbut couldn't find the answer quickly.
  • 我查了手册,和你一样。
  • 我在 上找到了 MySQL Internals 文档FLUSH TABLES,但没有具体说明。
  • 我什至阅读了源代码,mysql_server/sql/sql_base.cc但无法快速找到答案。

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.

根据内部文档,MySQL 表缓存保存最近使用的表的列表。没有提到特定于数据库的表缓存,MySQL 服务器中似乎只有一个表缓存。

FLUSH TABLESis 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.

FLUSH TABLES被描述为强制关闭所有打开的表(表缓存中的表)。没有提到这仅限于一个数据库,但您可以在 的参数中指定单个表FLUSH TABLES。同样,我假设默认情况下这适用于整个表缓存,因此适用于 MySQL 服务器上打开文件的所有数据库。

回答by Bill Karwin

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

例如,当您只执行 mysql_connect 然后“显示表”时 -> mysql_error(): No Database selected

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

使用“刷新表”没有 mysql_error,所以我认为答案是每个数据库