## Prerequisites
Before running the script, you must ensure the two servers can talk to each other and the destination database user exists.
### 1. Setup SSH Key Authentication
The "Sender" (Source) server needs to SSH into the "Receiver" (Destination) server without a password prompt.
* **On the Sender Server:**
Generate an SSH key if you haven't already:
```bash
ssh-keygen -t rsa -b 4096
(Press Enter through all prompts)
Copy the public key to the Receiver server (replace placeholders with actual values):
# Syntax: ssh-copy-id <remote_user>@<remote_ip>
ssh-copy-id [email protected]
(You will be asked for the remote user's password one last time)
- Test the connection:
(If you log in without a password, it's working)
The script attempts to create the database structure, but the Database User must typically already exist on the Receiver server for authentication to work initially.
- On the Receiver Server (or via Ploi/Forge Panel): Create a new database user.
- Username: (e.g.,
my_app) - Password: (Keep this handy; you will paste it into the script prompt)
- Privileges: Ensure this user has
ALL PRIVILEGESon their own database (or specificallyCREATE, INSERT, SELECT, UPDATE, DELETE).
- Edit the Configuration:
Open
mysql-ssh-migrator.shand update the following variables at the top:
SOURCE_USER/SOURCE_PASS: Your local database credentials.DEST_SSH_USER: The remote system user (e.g.,ploi,root, orubuntu).DEST_SSH_HOST: The remote server IP address.
- Make Executable:
chmod +x mysql-ssh-migrator.sh
- Run:
./mysql-ssh-migrator.sh
- Follow Prompts:
- Source DB Name: The name of the DB on the server you are running the script on.
- Destination User: The username you created in step 2 (the script assumes DB Name = Username).