MySQL将表的校验和存储在另一个表中 [英] MySQL store checksum of tables in another table

查看:133
本文介绍了MySQL将表的校验和存储在另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:
我们有大型数据库,其中包含大量表。他们中的大多数(99%)正在使用innodb。
我们希望有一个日常过程来监视哪个表已被修改。由于他们使用innodb,因此

  SHOW table STATUS的 Update_time 的值information_schema; 

为空。
出于这个原因,我们要创建一个日常过程,该过程将每个表的校验和(以及与此相关的其他东西)存储在某个地方(最好是另一个表)。对此,我们将进行不同的检查。



问题:
我正在尝试使用



<$ db_schema.table_name中的p $ p> 校验和表;

返回具有2列的结果集表:表,校验和。
它给了我想要的值,但是我不能在select或insert语句中使用它。



我尝试了很多类似的事情:

 从中选择 checksum(来自db_schema.table_name的校验和表); 

或其他类似查询。但是我无法从结果集中提取数据。



有没有办法做到这一点?
预先感谢您的帮助。



编辑:最后,我要构建的是一个复杂的结果集,其中包含不同的信息(表模式,表名称,计数,校验和,日期时间:now()...)
然后,我将使用该结果集与昨天的值进行比较,并得出自己的统计信息。这就是为什么我要从该结果集中获取校验和。

解决方案

不可能直接使用CHECKSUM TABLE保存结果SQL。您不能在存储过程中使用准备好的语句或游标来使用校验和结果。



对于使用CHECKSUM = 1表参数的MyISAM表,您可以像这样简单地使用INFORMATION_SCHEMA:

 选择TABLE_NAME,从INFORMATION_SCHEMA.CHECKSUM.TABLES 
,其中TABLE_SCHEMA ='test'并且ENGINE ='MyISAM'
并且CHECKSUM不为空;


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.

解决方案

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;

这篇关于MySQL将表的校验和存储在另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆