Backing Up and Restoring MySQL over SSH
For anything bigger than a small site, phpMyAdmin struggles with imports and exports. Over SSH, two commands handle databases of any size.
Export
mysqldump writes the whole database to a file:
mysqldump -uUSERNAME -pPASSWORD DATABASE > backup.sql
Import
The mysql client reads the file back into an existing database:
mysql -uUSERNAME -pPASSWORD DATABASE < backup.sql
Safer passwords
Typing -p with no password makes MySQL prompt for it, so it does not end up in your shell history. For automated backups, store credentials in a protected ~/.my.cnf file instead.
Stuck on something similar? Our server and automation work team is happy to take a look.