Backing Up and Restoring MySQL over SSH

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.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.