MySQL store checksum of tables in another table

一曲冷凌霜 提交于 2020-01-05 04:05:19

问题


CONTEXT: we have big databases with loads of tables. Most of them (99%) are using innodb. we want to have a daily process that monitors which table has been modified. As they use innodb the value of Update_time from

SHOW table STATUS from information_schema;

is null. For that reason we want to create a daily procedure that will store the checksum (and other stuffs for that matters) of each table somewhere (preferably another table). On that, we will do different checks.

PROBLEM: I'm trying to use

checksum table from db_schema.table_name;

which returns a resultset-table with 2 columns: "table","checksum". It gives me the value I want but I'm not able to use it in a select or insert statement.

I tried a lot of things like:

select `checksum` from (checksum table from db_schema.table_name);

or other similar queries. But I'm not able to extract the data from the resultset.

Is there a way I can do that? Thanks in advance for your help.

EDIT: in the end what I want is to build a more complex resultset having different informations in it (table schema, table name, count, checksum, datetime:now()...) Then I'll use this resultset to compare with the values of yesterday and draw my own statistics. That's why I want to get the checksum from that resultset.


回答1:


There is no possibility to save the result of CHECKSUM TABLE directly using SQL. Neither can you use prepared statements or cursors in stored procedures to use the checksum result.

You best make a script around it, or download some popular tools doing it for you.

For MyISAM tables using the CHECKSUM=1 table argument, you can simply use INFORMATION_SCHEMA like this:

SELECT TABLE_NAME,CHECKSUM FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'test' AND ENGINE='MyISAM' 
      AND CHECKSUM IS NOT NULL;


来源:https://stackoverflow.com/questions/11237712/mysql-store-checksum-of-tables-in-another-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!