Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql – Detecting changes in data with a hash function over a part of table

Tags:

mysql

hash

md5

sha1

I need generate a single hash over some data in a table

CREATE TABLE Table1
(
       F1             INT          UNSIGNED NOT NULL AUTO_INCREMENT,
       F2              INT          default     NULL,
       F3               Varchar(50)  default     NULL,
      ..
       FN              INT          default     NULL,
       PRIMARY KEY (F1)
);

i.e. F1, F3,FN where F2=10

SELECT md5(CONCAT_WS('#',F1,F3,FN)) FROM Tabe1 WHERE F2=10

Gives a Hash for each row in the table.

QUESTIONS

1) How do get a single hash over the whole table?

2) What is the fasts hashing algorithm to use MD5, SHA1, SHA or any other?

EDIT:

Mysql 4.1 is been used - and it does NOT have Trigger Support

like image 701
Charles Faiga Avatar asked Jun 23 '10 15:06

Charles Faiga


2 Answers

Altough this thread is old, maybe this is what you need: http://dev.mysql.com/doc/refman/5.0/en/checksum-table.html

like image 175
kraftb Avatar answered Nov 14 '22 10:11

kraftb


See BIT_XOR: http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html "Returns the bitwise XOR of all bits in expr. The calculation is performed with 64-bit (BIGINT) precision. This function returns 0 if there were no matching rows." For an example of usage, check pt-table-sync.

like image 42
Ruud H.G. van Tol Avatar answered Nov 14 '22 09:11

Ruud H.G. van Tol