Procedures for transferring MySQL databases from one server to another in SSH

When doing a site transfer or a database restore you may need to transfer a MySQL database from one FTP server to another.
The solution we will offer you is to save the database on the FTP and insert it directly into SSH.
Here we will add a step to know how to save the database in SSH and transfer this database directly from server to server without going through your machine (so no more worries of bandwidth).

We will admit here that you know how to connect in SSH on your server.

To save the database:
mysqldump -h votre.server.com -u User -p Database > backup.sql

To transfer the database from one server to another:
The easiest way is to connect to FTP on the host server via the server on which we have to recover the database.

We connect
ftp votre.site.com
We recover
mget backup.sql (and we validate)

To restore the database:
mysql -h votre.server.com -u User -p Database < backup.sql

It is also possible to back up the database directly to the target server directly to save time if you do not need to backup to your first server.