我想对 MySQL 数据库模式(没有数据)进行哈希/签名,以便对其进行校验和,以确保它不会被其他人修改。
我怎样才能实现它?
据我了解您的问题,您需要表格校验和:
checksum table `table`
所以,我猜只是做一个空表的校验和
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';