简体   繁体   English

vaccumm mysql? 缩小文件大小

[英]vaccumm mysql? shrink file size

Because of a bug i had inserted a LOT of rows in one table. 由于一个错误,我在一个表中插入了很多行。 I deleetd the rows but my db is >1gb instead of being 200mb. 我删除了行,但我的数据库是> 1gb而不是200mb。 How do i vaccumm it? 我该如何吸真空? I trid optimizing the table. 我尝试优化表。 It didnt shrink the size. 它没有缩小尺寸。 Am i stuck with this huge mysql file? 我会卡在这个巨大的mysql文件中吗?

Create an identical table structure, select * into newtable from oldtable then drop oldtable then alter table newtable rename oldtable . 创建一个相同的表结构, select * into newtable from oldtable然后drop oldtable然后alter table newtable rename oldtable The quickest cross-platform way. 最快的跨平台方式。

(In mysql you can use rename table newtable to oldtable , but that's not standard sql.) (在mysql中,您可以使用rename table newtable to oldtable ,但这不是标准的sql。)

One caveat, this only works if mysql is set up to be one file per table, which is the default AFAIK, but it can also be set up to be all tables in one file. 请注意,只有将mysql设置为每个表一个文件,这是默认的AFAIK,这才起作用,但是也可以将它设置为一个文件中的所有表。 If it's set up that way, you'll have to clone the entire database , a much more significant undertaking. 如果采用这种方式设置,则必须克隆整个数据库 ,这是一项更为重要的任务。 If you have a single "ibdata" file, you have all tables in one file, and you should probably see this answer . 如果只有一个“ ibdata”文件,则所有表都在一个文件中,您可能应该会看到此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM