The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another server. The mysqldump command can also generate output in CSV, other delimited text, or XML format. Although it appears to be a little executable file, its scope is greater to accommodate a variety of use-cases.
mysqldump accepts various connection options, DDL Options, Format Options, Filtering Options, Performance Options, Transactional Options, etc.
This post will show you how to take a backup of all databases using mysqldump and create separate files per database. It means a file for every database.
mysql -s -r -h awsinstance.com -u root -p -e ‘show databases’ -N |
while read dbname;
do mysqldump -h awsinstance.com -P 3306 -u root -p
–default-character-set=utf8mb4
–set-gtid-purged=OFF
–hex-blob
–triggers
–routines
–complete-insert
–single-transaction “$dbname” > “$dbname”.sql;
done
Change your instance name, credentials, and preferences based on your requirement.
mysqldump backups a database with just one transaction when using the –single-transaction option. This ensures that the database maintains a consistent state during the backup process by executing the whole backup procedure within a single transaction.
–triggers option allows to include the triggers.
–routines option allows to include the stored procedures/user-defined functions.
–complete-insert option is to include column names in the INSERT statements.
Hope you find the article helpful. If you need more clarification, drop a message.