是否使用“CREATE TEMPORARY TABLE”创建的表?在内存中还是在磁盘上?
在MySQL中,当您创建临时表时,例如CREATE TEMPORARY TABLE ...
,该表是创建并保存在内存中还是磁盘上?
我已经阅读了文档并用谷歌搜索了它,但还没有找到答案。
In MySQL, when you create a temporary table, for example, CREATE TEMPORARY TABLE ...
, is that table created and held in memory or on the disk?
I have read through the docs and Google'd it and have not come up with an answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您指定的引擎。默认情况下,表数据将存储在磁盘上。如果指定MEMORY引擎,数据将只存储在内存中。
应该可以实际找到创建临时表时在文件系统中创建的文件。运行以下命令后:
然后检查目录:C:\ProgramData\MySQL\MySQL Server 5.5\data\test(在 Windows 上),存在的文件为:
临时表存储在 C:\Windows\Temp 中并具有不常见的名称,但内部数据以相同的方式存储。
It depends on what engine you specify. By default the table data will be stored on disk. If you specify the MEMORY engine, the data will only be stored in memory.
It should be possible to actually find the files that are created in the filesystem when the temporary tables are created. After running the following commands:
I then checked the directory: C:\ProgramData\MySQL\MySQL Server 5.5\data\test (on Windows) and the files present were:
The temporary tables are stored in C:\Windows\Temp and have unusual names, but internally the data is stored in the same way.
就像马克所说,这取决于你告诉它使用什么引擎。如果您不提供引擎,它会做“某事”,但不一定将其保留在内存中。如果你想强制表位于内存中,你必须显式定义它:
但是,MEMORY-engine 的使用受到限制。有关更多信息,请参阅 内部临时表使用MySQL。
Like Mark said, it depends on what ENGINE you tell it to use. If you don't give an ENGINE, it will do "something", but not necessarily keep it just in memory. If you want to force the table to be in memory, you have to define it explicitly:
However, the use of MEMORY-engine is restricted. For more information have a look at Internal Temporary Table Use in MySQL.