mysqldump
Backup
To make a backup of a single database...
mysqldump -u myuser -p myDB > backup-myDB.sql
Backup entire DBMS (all tables consistent)...
mysqldump -A -R -E --single-transaction --quick --lock-tables=false >full-backup-$(date +%F).sql -u root -p
To create a dump file suitable for moving a database from one instance to another...
mysqldump -u myuser -p --single-transaction --databases myDB --result-file backup-myDB.sql
To dump just stored procedures, functions and triggers for all databases...
mysqldump -h myhost -u myuser -p -n -d -t --routines --all-databases > routines.sql
mysqldump -h myhost -u myuser -p --no-create-db --no-data --no-create-info --routines --all-databases > routines.sql
For a specific database...
mysqldump -h myhost -u myuser -p --no-create-db --no-data --no-create-info --routines --databases mydatabase > routines.sql
-R-t>
-A-E
Dump tables row by row, avoiding difficulties of buffering large amounts of data in memoryIgnore named tableDumps binary strings to hexadecimalConditional dump
Restore
To load the dump file back into the server:
mysql myDB < backup-myDB.sql
Alternatively...
mysql -e "source /path-to-backup/backup-myDB.sql" myDB
Backup Script
sudo -u mysql -s vi mysql-backup.sh
sudo -u mysql -s crontab -e
Bibliography
8.0https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
5.6https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html