Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:linux:mysql:backup [2023/10/24 19:33] – angelegt psycore | en:linux:mysql:backup [2024/01/09 15:09] (current) – Automatic translation 217.113.194.234 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== MySQL backup | + | {{tag> |
| + | ====== MySQL Backup | ||
| ===== Introduction ===== | ===== Introduction ===== | ||
| - | Nowadays it is impossible to imagine a server without | + | MySQL databases |
| - | To ensure that databases are still available after a system crash, it is necessary to back them up regularly. | + | To ensure that databases are still available |
| ===== mysqldump ===== | ===== mysqldump ===== | ||
| Line 11: | Line 12: | ||
| MySQL comes with a tool called mysqldump. With this tool it is possible to make a backup of all databases. Modern systems work with a password-protected query. For this reason, I will only present this variant here. | MySQL comes with a tool called mysqldump. With this tool it is possible to make a backup of all databases. Modern systems work with a password-protected query. For this reason, I will only present this variant here. | ||
| - | If we call mysqldump without parameters, we get the following | + | If we call mysqldump without parameters, we get the following |
| <code bash> | <code bash> | ||
| Line 27: | Line 28: | ||
| all available options are displayed. However, not all of these are relevant for a backup. The most important options for us are: -u -p | all available options are displayed. However, not all of these are relevant for a backup. The most important options for us are: -u -p | ||
| - | The option | + | The -u option |
| ===== Backing up the MySQL database ===== | ===== Backing up the MySQL database ===== | ||
| Line 37: | Line 38: | ||
| <code bash>$ mysqldump -u USER -p database USERDATABASE > usr1_db.sql</ | <code bash>$ mysqldump -u USER -p database USERDATABASE > usr1_db.sql</ | ||
| - | USER corresponds to the user here. The option | + | USER corresponds to the user. The -p option |
| - | ==== Back up all databases ==== | + | ==== Backing |
| - | To backup | + | To back up all databases, we must log in as MySQL root. The following syntax is used, which is similar to the one described above: |
| <code bash>$ mysqldump -u USER -p --all-databases > full_db.sql</ | <code bash>$ mysqldump -u USER -p --all-databases > full_db.sql</ | ||
| - | ===== Restore | + | ===== Restoring |
| - | Importing a dump file is just as easy. For this we use the following syntax: | + | Importing a dump file is just as easy. We use the following syntax |
| <code bash>$ mysql -p USERDATABASE -u USER -p < usr1_db.sql</ | <code bash>$ mysql -p USERDATABASE -u USER -p < usr1_db.sql</ | ||
| Line 58: | Line 59: | ||
| ===== Automated backup ===== | ===== Automated backup ===== | ||
| - | To back up the database automatically, | + | To back up the database automatically, |
| <code bash> | <code bash> | ||
| Line 103: | Line 104: | ||
| <code bash> | <code bash> | ||
| - | Create | + | create |
| <code bash>55 2 * * * root / | <code bash>55 2 * * * root / | ||