Skip to content

A Python tool for exporting MySQL databases with automatic dependency installation, real-time progress tracking, and gzip compression. No mysqldump required - works with local and cloud databases (AWS RDS, Google Cloud SQL, Azure).

License

Notifications You must be signed in to change notification settings

phpsmashcode/mysql-database-exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

MySQL Database Exporter

A powerful, user-friendly Python tool for exporting MySQL databases with automatic dependency management, progress tracking, and gzip compression support.

✨ Features

  • 🚀 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

🎯 Requirements

  • Python 3.6 or higher
  • Internet connection (for first-time dependency installation)

That's it! All other dependencies are installed automatically.

📥 Installation

# 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.py

🚀 Usage

Simply run the script and follow the interactive prompts:

python mysql_exporter.py

Interactive Prompts

The script will ask you for:

  1. Database Host - Your MySQL server address (e.g., localhost, 192.168.1.100, or db.example.com)
  2. Database Port - Default is 3306
  3. Username - Your database username
  4. Password - Securely hidden during input
  5. Database Name - The database you want to export
  6. Export Directory - Where to save the backup (default: current folder)
  7. Compression - Whether to compress with gzip (recommended)

Example Session

=== 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%
============================================================

📦 What Gets Installed Automatically

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.

🌟 Use Cases

  • 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

🔧 Advanced Features

Compression

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

Progress Tracking

  • Main progress bar shows table-by-table export
  • Nested progress bars for large tables (>1000 rows)
  • Real-time ETA and speed metrics

Batch Processing

INSERT statements are batched in groups of 100 rows for optimal performance and memory usage.

🛡️ Security Features

  • Password input is hidden using getpass
  • SSL/TLS support for secure connections
  • No password stored in command history
  • Safe for production database connections

📝 Export Format

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

🐛 Troubleshooting

Connection Issues

If you get connection errors:

  1. Check credentials - Verify username and password
  2. Firewall rules - Ensure your IP is allowed
  3. SSL requirements - RDS and cloud databases often require SSL
  4. Network access - Verify database host is reachable

Dependency Installation Fails

If automatic installation fails:

pip install mysql-connector-python tqdm

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

👨‍💻 Author

Created by phpsmashcode

⭐ Support

If you find this tool helpful, please give it a star on GitHub!

🔗 Related Projects


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.

About

A Python tool for exporting MySQL databases with automatic dependency installation, real-time progress tracking, and gzip compression. No mysqldump required - works with local and cloud databases (AWS RDS, Google Cloud SQL, Azure).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages