Database Schema Comparison & Synchronization Tool
DbMySync is a powerful PHP-based tool for comparing MySQL database schemas between different environments (Dev, Staging, Production) and generating SQL statements to synchronize them.
- 🔍 Schema Comparison: Compare database schemas between two environments
- 📊 Detailed Diff View: See differences in tables, columns, indexes, and foreign keys
- 🛠️ SQL Generation: Automatically generate SQL statements to sync databases
- 🎯 Granular Control: Generate SQL for specific tables, columns, or changes
- 🔐 Secure API: Token-based authentication for endpoint access
- 🎨 Modern UI: Clean, responsive interface with modal dialogs
- 📋 Copy to Clipboard: One-click copy of generated SQL statements
- 🔄 Bidirectional Sync: Sync from Dev to Prod or Prod to Dev
- ✅ Missing tables in either environment
- ✅ Complete CREATE TABLE statements with all constraints
- ✅ Missing columns
- ✅ Different data types
- ✅ Different nullable settings
- ✅ Different default values
- ✅ Different charset/collation
- ✅ Different extra attributes (auto_increment, etc.)
- ✅ Missing indexes
- ✅ Different index types (UNIQUE, KEY)
- ✅ Different indexed columns
- ✅ Missing foreign keys
- ✅ Different referenced tables/columns
- ✅ Different ON DELETE/UPDATE actions
- PHP 7.4 or higher
- MySQL 5.7 or higher
- Composer
- Apache/Nginx with mod_rewrite
git clone https://github.com/Jensovic/dbmysync-app.git
cd dbmysync-appMain Application:
cd main-application
composer installEndpoint:
cd ../endpoint
composer installMain Application:
- The SQLite database will be created automatically at
main-application/data/dbmysync.db - Import the schema:
sqlite3 data/dbmysync.db < database/schema.sql
Endpoint:
cd endpoint/config
cp config.example.php config.phpEdit config.php with your database credentials:
return [
'db_host' => 'localhost',
'db_name' => 'your_database',
'db_user' => 'your_username',
'db_pass' => 'your_password',
'api_token' => 'your-secure-random-token-here'
];Apache (.htaccess included):
- Point your virtual host to
main-application/public/for the main app - Point another virtual host to
endpoint/public/for the endpoint
Nginx:
server {
listen 80;
server_name dbmysync.local;
root /path/to/dbmysync-app/main-application/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}- Open the main application in your browser
- Click "Add New Tool Pair"
- Enter names for both environments (e.g., "Production" and "Development")
- Enter the endpoint URLs and API tokens
- Save
- Click "Compare" on your tool pair
- View the detailed comparison results
- See differences in tables, columns, indexes, and foreign keys
- Click "SQL to adjust Prod" to sync Production with Development
- Click "SQL to adjust Dev" to sync Development with Production
- Use granular buttons for specific tables or columns
- Copy the generated SQL and execute it in your database
dbmysync-app/
├── main-application/ # Main web interface
│ ├── public/ # Web root
│ ├── src/ # PHP classes
│ ├── views/ # HTML templates
│ ├── data/ # SQLite database
│ └── database/ # SQL schemas
│
├── endpoint/ # API endpoint (deploy on each server)
│ ├── public/ # Web root
│ ├── src/ # API logic
│ └── config/ # Database configuration
│
└── test-installation/ # Test scripts
- ✅ Token-based API authentication
- ✅ SQL injection protection via PDO prepared statements
- ✅ No passwords stored in main application
- ✅ HTTPS recommended for production use
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Jensovic
- GitHub: @Jensovic
- Built with PHP and love ❤️
- Uses Guzzle for HTTP requests
- SQLite for local data storage
⭐ If you find this tool useful, please consider giving it a star!