Table of Contents

Ubuntu - Backups - Backup and restore mysql databases

To backup (dump) a single mysql database to a file

mysqldump -u foo -p foodb > foodb.sql

where:


To backup (dump) all databases to a file

mysqldump -u foo -p --all-databases > alldb.sql

where:


To restore a mysql database from dumpfile

1. From terminal

mysql -u foo -p foodb < foodb.sql

where:


2. From inside mysql console where you have to access mysql console first:

mysql> source foodb.sql 
 
or 
 
mysql> \. foodb.sql

where foodb.sql is the dumpfile.