Hash MySQL database schema

后端 未结 2 1441
北荒
北荒 2021-02-15 22:44

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 ach

2条回答
  •  清酒与你
    2021-02-15 23:32

    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';
    

提交回复
热议问题