hi,
i looking for a free software or php script that can compare a database
from server 1 and beetween server 2 and creat the tables and fields that are missing.
any one have know a solution?
thanks for your help
:)

Dani AI

Generated

Short answer: you can do this for free, but fully automatic "push changes and forget" is risky. asked for a no‑human‑intervention solution; pointed out commercial tools and mentioned PHP options. Below are free, practical alternatives and a safe workflow you can apply today.

Free options to consider (quick notes):

  • MySQL Workbench: built‑in schema compare/synchronize (nice GUI, generates ALTER/CREATE SQL you can review).
  • MySQL Utilities (mysqldiff / mysqldbcompare): command‑line utilities that produce sync SQL; good for automation scripts.
  • Liquibase: can run a diff and produce a changelog you apply under version control (better for repeatable, audited changes).
  • Simple export+diff: export schemas with mysqldump --no-data and use diff or a text diff tool if you prefer minimal dependencies.
  • Percona Toolkit: use pt-table-sync for data-level syncing and pt-online-schema-change when you must alter big tables online (note: Percona tools are mostly for data and online DDL, not full schema diff).

Safe automated workflow (recommended):

  1. Always back up the target (mysqldump or LVM/snapshot).
  2. Generate the diff but do not apply it automatically. Use mysqldiff/mysqldbcompare or dump schemas and diff them.
  3. Review generated SQL to catch DROP/rename/destructive ops.
  4. Test the SQL on a staging copy.
  5. Apply during a maintenance window or through an automated migration tool (Liquibase/Flyway) that requires an owner to approve change sets.

If you want a short PHP approach: compare INFORMATION_SCHEMA metadata and use SHOW CREATE TABLE to copy missing tables, and information_schema.COLUMNS to build ALTER TABLE ADD COLUMN statements. Example outline:

$src = new PDO(...);
$dst = new PDO(...);
$tables = $src->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
foreach ($tables as $t) {
  $exists = $dst->prepare("SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA=? AND TABLE_NAME=?");
  $exists->execute([$dstDb,$t]);
  if (!$exists->fetch()) {
    $ddl = $src->query("SHOW CREATE TABLE `$t`")->fetch(PDO::FETCH_ASSOC)['Create Table'];
    $dst->exec($ddl);
  } else {
    // compare information_schema.COLUMNS and create ALTER TABLE ADD COLUMN statements
  }
}

Cautions: DDL is rarely transactional; replication, collation, indexes, triggers and stored routines can be missed by simple tools; ensure proper privileges; always test backups and staging first.

Recommended Answers

All 4 Replies

I use Navicat to do that. It is not free, but it does have a 30 day trial.

hi,
i looking for a free software or php script that can compare a database
from server 1 and beetween server 2 and creat the tables and fields that are missing.
any one have know a solution?
thanks for your help
:)

hi,
i already use that a very old version but that can this,
what i looking for is a alternative for do this alone without human interv.
thanks

hi
another php calss for sync mysql database

thanks
Tariq Shraim

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.