简体   繁体   English

MySQL将表的校验和存储在另一个表中

[英]MySQL store checksum of tables in another table

CONTEXT: we have big databases with loads of tables. 语境:我们有大型数据库,其中包含大量表。 Most of them (99%) are using innodb. 他们中的大多数(99%)正在使用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 当他们使用innodb时, Update_time的值从

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. 它给了我想要的值,但是我不能在select或insert语句中使用它。

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. 编辑:最后,我要构建的是一个复杂的结果集,其中包含不同的信息(表架构,表名称,计数,校验和,datetime:now()...),然后将使用此结果集进行比较昨天的值并得出我自己的统计数据。 That's why I want to get the checksum from that resultset. 这就是为什么我要从该结果集中获取校验和的原因。

There is no possibility to save the result of CHECKSUM TABLE directly using SQL. 无法直接使用SQL保存CHECKSUM TABLE的结果。 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: 对于使用CHECKSUM = 1表参数的MyISAM表,您可以像下面这样简单地使用INFORMATION_SCHEMA:

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

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

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