Compare Two MySQL Databases Using MySQL Workbench – Step-by-Step Guide

Learn how to compare two MySQL databases using MySQL Workbench. Identify schema differences, generate synchronization scripts, and keep your environments in sync.

When working on database-driven applications, it’s common to maintain multiple copies of a MySQL database — such as development, staging, and production. Over time, these environments may drift out of sync, making it essential to compare the database schemas to identify differences.

In this article, you’ll learn how to compare two MySQL databases using MySQL Workbench, and how to synchronize or export the differences between them.

Why Compare Databases?

Database comparison is especially useful for:

  • Identifying schema differences between environments
  • Detecting missing tables, columns, or indexes
  • Preparing migration scripts
  • Ensuring version control for database structures

Tools Required

To perform the comparison, you’ll need:

  • Connection credentials for both databases (source and target)
  • MySQL Workbench (preferably version 6.3 or later)

Steps to Compare Two MySQL Databases

Open MySQL Workbench

Launch the Workbench and make sure both databases (e.g., dev_db and prod_db) are accessible via configured connections.

Go to “Database” → “Compare Schemas”

From the top menu, go to:

Database → Compare Schemas

This opens a new window where you can choose the source and target schemas.

Select Source and Target Schemas

  • Source: Select the original or current version of your database (e.g., dev_db)
  • Target: Select the database you want to compare against (e.g., prod_db)
  • Click “Next” to proceed.

Start Comparison

MySQL Workbench will analyze both databases and show the results in terms of:

  • Tables only present in one database
  • Tables that exist in both but have structural differences
  • Differences in columns, indexes, constraints, routines, views, triggers, etc.

Review the Differences

You’ll be presented with a detailed comparison table showing:

  • Objects to add, modify, or drop
  • SQL scripts representing those changes

This is useful for developers and DBAs to audit what’s changed or to plan a synchronization.

Synchronize or Export Differences (Optional)

You can either:

  • Synchronize directly from source to target using MySQL Workbench
  • Or export the SQL script to apply changes manually after review

Warning: Always back up your databases before applying synchronization scripts to avoid accidental data loss.

Use Case Example

Let’s say you added a new table and modified a few column types in your development database. By using MySQL Workbench’s schema comparison, you can quickly identify those changes and generate a script to apply them to production without having to track each change manually.

Conclusion

MySQL Workbench provides a powerful built-in Schema Comparison Tool that helps you:

  • Identify differences between two MySQL databases
  • Review structural changes in tables, views, routines, and more
  • Generate SQL scripts to synchronize schemas safely

This feature is invaluable for teams managing multiple environments or collaborating on large database projects.

For more information about MySQL Workbench, visit http://www.mysql.com/products/workbench/
MySQL Workbench is freely available at http://www.mysql.com/downloads/workbench/.

How to Detect Unused CSS Selectors and Remove Them from Your Website

Improve website performance by identifying and removing unused CSS selectors. Learn effective tools and methods to clean up your stylesheets.

During the development, we forget to remove selectors, which have been changed during the different phases of the website, Which makes stylesheet file so large. Due to which, stylesheets load slower, which makes the website load slower. So, this is necessary to remove unused css rules from stylesheets to make a website load faster.

There are so many online tools, Firefox Extension as well as commercial products to do that.

Firefox Development Tool: Dust-Me Selectors
It scans your HTML pages and find the unused CSS selectors. It takes all CSS selectors from all stylesheets attached to the page you are viewing and then scan that page to find the unused selectors. It stores data separately for each website you viewed.

Disadvantage: It just gives you the unused selectors, but not providing the updated stylesheet.

Dead Weight: Ruby Gem
It is a CSS coverage tool and only works for rails website. You need to provide a set of stylesheets and URLs, from which it provides a list of selectors which can be “safely” deleted. You can manually remove them from the stylesheet using that list.

You can watch the screen-cast on Dead Weight Introduction at http://railscasts.com/episodes/180-finding-unused-css

Unused-CSS.com: Online Tool
It asks for an online URL to check. From the URL, It scans all CSS files and show the results separately for each stylesheet with graphs. Currently it scans only homepage, but if you need whole website results, you need to provide your e-mail address and it will send the results to you in email.

Helium CSS: Javascript Tool
It is a javascript-based tool and runs from the browser. It is a used for discovering unused selectors across many pages on a web site. It accepts only list of URLs, parses each URL provided and build a list of stylesheets. Using this list of stylesheets and URLs, it generates a list of unused selectors not used in any of the URL provided.

TopStyle 5: Windows Application
It is an HTML Editor, which includes a tool named Style Sweeper. Style sweeper can remove white spaces and blank lines, sort according to Class, Element, ID and also combines multiple selectors. It will also combine repeated property as well as selectors if they are same. But it’s a commercial product costs $80 (USD).

LiquidCity CSS Cleaner: PHP Script
It uses regular expressions to check any HTML page specified by you, generates the report with unused selectors for that HTML page only. From that report, you can manually remove them from the stylesheet.

There are so many other tools available. We will introduce them very soon.