Hash MySQL database schema

后端 未结 2 903
臣服心动
臣服心动 2021-02-15 22:32

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:20

    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

    0 讨论(0)
  • 2021-02-15 23:21
    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';
    
    0 讨论(0)
提交回复
热议问题