Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hash MySQL database schema

Tags:

mysql

checksum

I would like to make a hash / signature of MySQL database schema (without data), in order to have a checksum of it, to ensure it is not modified by others.

How can I achieve it ?

like image 395
Raptor Avatar asked Oct 11 '12 03:10

Raptor


2 Answers

You need table checksum as far as I understand your question:

checksum table `table`

so, just make a checksum of an empty table, I guess

like image 120
Nemoden Avatar answered Nov 12 '22 09:11

Nemoden


SELECT HEX( CRC32 ( SUM( CRC32( CONCAT(
   COALESCE(TABLE_NAME,''),
   COALESCE(COLUMN_NAME,''),
   COALESCE(ORDINAL_POSITION,''),
   COALESCE(COLUMN_DEFAULT,''),
   COALESCE(IS_NULLABLE,''),
   COALESCE(DATA_TYPE,''),
   COALESCE(CHARACTER_MAXIMUM_LENGTH,''),
   COALESCE(CHARACTER_OCTET_LENGTH,''),
   COALESCE(NUMERIC_PRECISION,''),
   COALESCE(NUMERIC_SCALE,''),
   COALESCE(CHARACTER_SET_NAME,''),
   COALESCE(COLLATION_NAME,''),
   COALESCE(COLLATION_NAME,''),
   COALESCE(COLUMN_TYPE,''),
   COALESCE(COLUMN_KEY,'')
  ) ) ) ) ) AS 'hash'
FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'database_name';
like image 45
Евгений Кочетков Avatar answered Nov 12 '22 08:11

Евгений Кочетков