User Tools

Site Tools


linux:ubuntu_mysql_database_backup

Ubuntu Database Backup

Note: This will work on other systems as well and also on MySQL Databases not only MariaDB.

Find the databases that are present on the server

mysql -u root -p
show databases;
exit

Make a note of the database you which to backup. Them make sure nothing writes to the database before you continue. If you are not sure whether stuff is still getting written to the database. You can lock the tables like this.

mysql -u root -p
FLUSH TABLES WITH READ LOCK;
exit

Now we can backup the database in this example we are backing up the a database called pineapple.

mysqldump -u root -p pineapple > pineapple.dd.mm.yyyy.sql

Now we can unlock the tables again.

mysql -u root -p
UNLOCK TABLES;
exit

Compressed Backup

Tip: On large databases or systems with low disk space you can choose to compress it during the dump.

mysqldump -u root -p pineapple | gzip > pineapple.dd.mm.yyyy.sql.gz

Importing A Compressed Backup

gunzip < pineapple.dd.mm.yyyy.sql.gz | mysql -u root -p pineapple

Or

zcat pineapple.dd.mm.yyyy.sql.gz | mysql -u root -p pineapple
linux/ubuntu_mysql_database_backup.txt · Last modified: 24/11/2023 12:23 by Allan