The mysqldump command can be used to backup one or more MySQL or MariaDB databases.
Before issuing the mysqldump command, you may want to issue the flush tables with read lock command to disable write access to tables. The tables will continue to have read access.
mysql -e "flush tables with read lock"
To backup a single database, including all of the tables in the database.
mysqldump --user=root --password=itsasecret --databases database_name > /path/to/directory/backup.sql
Or, if you have configured passwordless authentication then there is no need to include the --user and --password options.
mysqldump --databases database_name > /path/to/directory/backup.sql
To backup a single table in a database.
mysqldump database_name table_name > /path/to/directory/backup.sql
The --all-databases option can be used to backup every database.
mysqldump --all-databases > /path/to/directory/backup.sql
gzip can be used to create a gzip compressed file.
mysqldump --all-databases | gzip > /path/to/directory/backup.sql.gz
The backup.sql file will contain all of the commands that are needed to recreate the tables in the database, and to insert all of the data into the tables.
If you issued the flush tables with read lock command to disable write access to tables, use the unlock tables command to remove the lock, restoring write access to the tables.
mysql -e "unlock tables"