Bootstrap FreeKB - mySQL / MariaDB - Back up a mySQL or MariaDB database using the mysqldump command
mySQL / MariaDB - Back up a mySQL or MariaDB database using the mysqldump command

Updated:   |  mySQL / MariaDB articles

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"

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 95926e in the box below so that we can be sure you are a human.