How do I get a backup of my MySQL database?

Linode Staff

I have a MySQL database running on my Linode. How can I download a backup of that data?

2 Replies

There are two steps when downloading a backup of your database:

  1. Move your database's data into a file that you can copy off of your server.
  2. Download that file using a file transfer tool.

Moving your data into a file

There's two ways to do this for MySQL:

You can use the mysqldump tool to 'dump' your data into a file. Your MySQL service needs to be running in order to do this. This guide covers how to use this tool:

Use mysqldump to Back Up MySQL or MariaDB

Alternatively, you can create a 'physical' backup file. You would do this if you can't run MySQL normally for some reason, and you should only do this while MySQL isn't running. This guide outlines that process:

Create Physical Backups of your MariaDB or MySQL Databases

Downloading your MySQL backup file

You have a few options for downloading the file. This guide describes how to use the rsync command line tool:

Backing Up Your Data

You could also use a visual SFTP app like FileZilla to grab the file:

Transfer Files with FileZilla

As @nmelehan said, mysqldump is the way to go.

But keep in mind that there are caveats - if you don't do it correctly, you'll get a corrupt data.

  • Set --default-character-set=binary or you will get "?" for all emojis, even if you have set utf8mb4 on your server.
  • For InnoDB, --single-transaction is a must option, or you may get an inconsistent state - broken references to a foreign key, etc.
  • If any one of your tables includes MyISAM, make sure you have an option that includes --lock-tables, or the dump can be completely broken.
  • Version mismatch of server / client can fail to perform backup, especially before and after MySQL 5.6.

And many more subtle problems that you only notice when you need a backup.

Unfortunately, these are the artifact of MySQL's winding legacy.

Or you can use a third party tool like https://dumper.io to get rid of those worries. (Disclosure: I'm the creator)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct