ubuntu:backups:backup_and_restore_mysql_databases
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:
- -u is for username.
- -p is for mysqldump to ask for password.
- foodb is the name of the database.
- foodb.sql is the file to dump the database.
To backup (dump) all databases to a file
mysqldump -u foo -p --all-databases > alldb.sql
where:
- -u is for username.
- -p is for mysqldump to ask for password.
- --all-databases is to tell mysqldump to dump all databases available.
- alldb.sql is the dumpfile name.
To restore a mysql database from dumpfile
1. From terminal
mysql -u foo -p foodb < foodb.sql
where:
- -u is for username.
- -p is for mysqldump to ask for password.
- foodb is the name of the database.
- foodb.sql is the file to dump the database.
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.
ubuntu/backups/backup_and_restore_mysql_databases.txt · Last modified: 2022/06/14 08:04 by peter