Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ MySQL to MySQL Live Database Transfer Script

A one-click bash script to securely dump, transfer, and import a MySQL/MariaDB database from one live server to another β€” all in one step.


✨ What You'll Get

βœ… Dump a source database
βœ… Securely transfer the dump via SSH
βœ… Automatically import into a destination MySQL/MariaDB server
βœ… Automatically clean up (.sql file deleted from both servers)
βœ… Easy-to-configure and reusable


πŸ“ File Structure

db/
β”œβ”€β”€ db.sh         # The main transfer script
└── README.md     # This documentation

βš™οΈ Requirements

  • Linux/macOS terminal (bash)
  • mysqldump, mysql installed (default in most systems)
  • sshpass for SSH automation (if not using SSH key)

πŸ”§ To install dependencies (Ubuntu/Debian):

sudo apt update
sudo apt install sshpass mysql-client -y

🧠 Configuration

  1. Open the script file:
nano db.sh
  1. Replace the following placeholders with your actual credentials:
# Source DB
SRC_DB="your_database"
SRC_USER="your_database_user"
SRC_PASS="your_source_db_password"

# Destination
DEST_HOST="your_IP"
DEST_DB="your_database"
DEST_USER="your_database_user"
DEST_PASS="your_dest_db_password"
DEST_SSH_USER="root"
DEST_SSH_PASS="your_ssh_password"

πŸš€ How to Run the Script

  1. Make the script executable:
chmod +x db.sh
  1. Run it:
./db.sh

βœ… That’s it β€” your database will be dumped, transferred, imported, and cleaned up in seconds.


🧹 Auto Cleanup

This script deletes the backup .sql file from both servers after the import is complete.

  • Local .sql file: deleted from the source server
  • Remote .sql file: deleted from the destination server after import

This ensures security and avoids disk clutter.


πŸ” Security Notes

  • This script uses plain-text passwords for MySQL and SSH. Only use on trusted environments.
  • For better security, consider:
    • SSH key authentication instead of sshpass
    • Using .my.cnf to store MySQL credentials securely

πŸ“¦ Example Output

πŸ“¦ Dumping source database (Database)...
🚚 Transferring backup to destination server (IP)...
πŸ“₯ Importing into destination database (Database)...
🧹 Deleting local backup file...
βœ… Transfer, import & cleanup complete!

🀝 Credits

Author: zamibd
License: MIT β€” free to use, modify, and distribute.


πŸ’¬ Need Help?

Feel free to open an issue or pull request on the GitHub repo.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages