Mysql - 查找未使用的表和列
假设我们有一个包含 MySQL 数据库和多个表的“系统 A”。 一段时间后,您希望通过删除任何未使用的表和/或列来优化系统 A,因为系统 A 相当大且难以忽视。是否有一种工具或方法可以让您运行系统一段时间,然后进行分析,打印出表、列等的一般使用情况,这样就可以找到未使用的表和列。
我正在考虑也许连接到系统,记录所有发送到服务器的 SQL 命令,但在这种情况下,宁愿在数据库端而不是应用程序端执行此操作。
Let's say we have "system A" comprising a MySQL database, with several tables.
After a while you want to optimize system A by removing any unused tables and/or columns, system A being quite large and difficult to overlook. Is there a tool or method that lets you run the system for a while, and then do an analysis which prints out general use of tables, columns etc - which would make it possible to find unused tables and columns.
I'm thinking of maybe hooking into the system, logging all SQL commands going to the server, but would in that case rather be doing that on the database side, rather than the application side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
常规查询日志可能就是您想要的寻找。
根据MySQL,使用通用查询登录:
您需要使用
--log[=file_name]
或-l [file_name]
选项启动 MySQL 才能使用它。The General Query Log is probably what you're looking for.
According to MySQL, with the General Query Log on:
You need to start MySQL with the
--log[=file_name]
or-l [file_name]
option in order to use it.假设您已经将数据库与某种应用程序链接起来,那么找到正在使用的列而不是未使用的列应该不难。
此外,诸如探查器之类的程序(不确定是否与 MySQL 等效)可用于显示所有 SQL 调用。由此您将了解正在使用的所有列。
Assuming you are already linking the database with an application of some sort, it shouldn't then be hard to find the columns that are being used over the columns that are not.
Further a program such as profiler (not sure on the MySQL equivalence) can be used to display all the SQL calls. From this you will know all the columns that are being used.