A powerful, user-friendly Python tool for exporting MySQL databases with automatic dependency management, progress tracking, and gzip compression support.
- 🚀 Zero Configuration - Auto-installs dependencies on first run
- 📊 Real-time Progress Bars - Visual feedback during export with tqdm
- 🗜️ Gzip Compression - Reduce file sizes by 60-70%
- 🔒 Secure Authentication - Hidden password input with SSL support
- ☁️ Cloud Database Support - Works with AWS RDS, Google Cloud SQL, Azure, etc.
- 💾 Smart Batching - Efficient memory usage for large databases
- 📈 Export Statistics - File size, compression ratio, and performance metrics
- 🎯 Pure Python - No mysqldump binary required
- Python 3.6 or higher
- Internet connection (for first-time dependency installation)
That's it! All other dependencies are installed automatically.
# Clone the repository
git clone https://github.com/phpsmashcode/mysql-database-exporter.git
# Navigate to the directory
cd mysql-database-exporter
# Run the script (dependencies auto-install on first run)
python mysql_exporter.pySimply run the script and follow the interactive prompts:
python mysql_exporter.pyThe script will ask you for:
- Database Host - Your MySQL server address (e.g.,
localhost,192.168.1.100, ordb.example.com) - Database Port - Default is 3306
- Username - Your database username
- Password - Securely hidden during input
- Database Name - The database you want to export
- Export Directory - Where to save the backup (default: current folder)
- Compression - Whether to compress with gzip (recommended)
=== MySQL Remote DB Export Tool (Python) ===
Enter database host: your-database.example.com
Enter database port (default: 3306):
Enter database username: your_username
Enter database password:
Enter database name: your_database
Enter export directory (default: current folder): backups
Compress output with gzip? (y/n, default: y): y
Connecting to database 'your_database' at your-database.example.com:3306 ...
✅ Connected successfully!
Fetching database structure...
Found 39 tables. Starting export...
Exporting tables: 100%|████████████████████████| 39/39 [00:59<00:00, 1.53s/table]
============================================================
✅ Export successful!
📁 File: backups/your_database_backup_20241028_143022.sql.gz
💾 Size: 12.45 MB
📊 Estimated uncompressed: ~37.35 MB
🗜️ Compression ratio: ~66.7%
============================================================
On first run, the script will automatically install:
- mysql-connector-python - MySQL database connector
- tqdm - Progress bar library
The script checks for these packages and only installs what's missing.
- Regular Backups - Schedule with cron/Task Scheduler
- Database Migration - Export from one server, import to another
- Development Snapshots - Quick local database copies
- Cloud Database Backups - AWS RDS, Google Cloud SQL, Azure MySQL
- Pre-deployment Backups - Safety net before major changes
The tool offers gzip compression which typically reduces file sizes by 60-70%:
- Compressed:
database_backup_20241028_143022.sql.gz - Uncompressed:
database_backup_20241028_143022.sql
- Main progress bar shows table-by-table export
- Nested progress bars for large tables (>1000 rows)
- Real-time ETA and speed metrics
INSERT statements are batched in groups of 100 rows for optimal performance and memory usage.
- Password input is hidden using
getpass - SSL/TLS support for secure connections
- No password stored in command history
- Safe for production database connections
The exported SQL file includes:
- Database and table structure (CREATE TABLE statements)
- Complete data (INSERT statements)
- Proper escaping for special characters
- Binary data handling (BLOB fields)
- Foreign key constraint management
If you get connection errors:
- Check credentials - Verify username and password
- Firewall rules - Ensure your IP is allowed
- SSL requirements - RDS and cloud databases often require SSL
- Network access - Verify database host is reachable
If automatic installation fails:
pip install mysql-connector-python tqdmContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Created by phpsmashcode
If you find this tool helpful, please give it a star on GitHub!
- mysqldump - Official MySQL backup tool
- mysql-connector-python - MySQL Python connector
Note: This tool creates logical backups (SQL dumps). For large production databases, consider using physical backup tools like MySQL Enterprise Backup or Percona XtraBackup for better performance.