确定 MySQL 中哪个表占用最多磁盘空间
确定哪个表占用最多磁盘空间的最简单方法是什么?
一个障碍:我没有 MySQL 服务器,只有包含所有数据的文件 (dump.sql)
What is the easiest way to determine which table takes most disk space ?
A handicap: I have no MySQL server, only the file with all data (dump.sql)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想要下载 MySQL 服务器,将其安装在本地主机上,导入转储文件,然后使用:
You may want to download MySQL server, install it on your localhost, import the dump file, and then use:
如果你在 Linux 上,你可以扫描转储文件中最长的行,这可能(也可能不是!)是最大的表,具体取决于索引、结构等,但如果你不能,这将是一个不错的猜测启动服务器。
这将显示最长行的前 100 个字符。例如,如果转储文件中的每个表有多个插入(使用
--extended-insert
或--opt
选项),则这可能不起作用。If you're on linux, you can scan the dump file for the longest line, which may (or may not!) be the largest table depending on indexes, structure etc, but it's going to be a decent guess if you can't get a server up.
This will show you the first 100 characters of the longest line. This may not work if you have, for example, multiple inserts per table in your dump file (with
--extended-insert
or--opt
options).一个快速的解决方案可能是对转储中的每个表执行类似的操作:(
我希望您使用的是 Linux,否则您可以安装 Cygwin 以在 Windows 系统上获取 Linux 命令行的一些功能)
此命令将过滤输出特定表的转储的插入语句,并打印出这些过滤插入语句的总字节数。当然,插入语句的大小与表中存储行的大小不同,但如果您只需要确定哪个表(可能)最大,那么它可能是一个很好的近似值。
A quick solution might be to do something like that for each table in the dump:
(I hope you are using Linux, otherwise you can install Cygwin to get some of the functionally of the linux command line on a windows system)
This command will filter out the inserts statements of the dump for a specific table and print out the total bytes of those filtered insert statements. Of course, the size of the insert statements isn't the same as the size of the stored rows in the table, but it might be a good approximation if you only need to decide which table is (probably) the largest.