Pre & Post Migration Activities

This article describes the required validation steps to be performed before and after database migration. These steps ensure data consistency, integrity, and completeness by capturing key database metrics. The captured values serve as a baseline for comparison after migration.

Prerequisites

Ensure the following conditions are met before proceeding:

  • Database Access: Access to both source and target database environments

  • Permissions: Required privileges to query information_schema

  • SQL Tool: Availability of a SQL client or query execution tool

  • Database Details: Database name identified for validation

Procedure

Execute the following scripts before and after the migration activity to validate consistency.

  1. Capture Table Row Counts

    • Run the following SQL query to retrieve table row counts and sizes. Save the output for post-migration comparison.

      USE information_schema;
      SELECT 
          TABLE_NAME AS "Table Name", 
          TABLE_ROWS AS "Row Count", 
          ROUND((COALESCE(DATA_LENGTH, 0) + COALESCE(INDEX_LENGTH, 0)) / 1024 / 1024) AS 
      "Size (MB)"
      FROM tables
      WHERE table_schema = 'YOUR_DB_NAME'
      UNION ALL
      SELECT 
          "Total Count", 
          SUM(RowCount), 
          SUM(Size)
      FROM (
          SELECT 
              TABLE_NAME AS "Table Name", 
              TABLE_ROWS AS "RowCount", 
              ROUND((COALESCE(DATA_LENGTH, 0) + COALESCE(INDEX_LENGTH, 0)) / 1024 / 1024) 
      AS "Size"
          FROM tables
          WHERE table_schema = 'YOUR_DB_NAME'
      ) summary;
      Reference: All_Tables_RowCount.sql

  2. Capture Database Size

    • Run the following SQL query to retrieve the total database size.

      SELECT 
          table_schema AS "Database Name", 
          ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS "DB Size (MB)"
      FROM information_schema.tables 
      GROUP BY table_schema;
  3. Verify Table Collation

    • Verify that all tables use the utf8mb4_0900_ai_ci collation. Check Collation:

      SELECT 
          TABLE_SCHEMA, 
          TABLE_NAME, 
          TABLE_COLLATION 
      FROM information_schema.tables 
      WHERE TABLE_COLLATION != 'utf8mb4_0900_ai_ci';

Copyright © 2026, OvalEdge LLC, Peachtree Corners, GA, USA.

Last updated

Was this helpful?